Question : Formatting on Excel Output from Access

Hi, i have the below code and i am looking to format the Columns C:F on output so that there is a comma in the numbers that are outputted e.g. 162,500 instead of 162500 and i would also like there to be only 2 decimal places given

This is my code

Private Sub Command0_Click()
Dim strFile As String
strFile = "F:\VarianceOutput.xls"
'DoCmd.OutputTo acOutputForm, Me.Variance, acFormatXLS, strFile, False
DoCmd.OutputTo acOutputTable, "Variance", acFormatXLS, strFile, False

Dim oXL As Object
Dim oWB As Object
Dim oWS As Object
Dim FormulaRow As Long
 
Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(strFile)
Set oWS = oWB.Sheets(1)
With oWS
    FormulaRow = .Cells(.Rows.Count, "d").End(-4162).Row + 2 'xlUp
    .range("c" & FormulaRow & ":f" & FormulaRow).Formula = "=SUM(c2:c" & (FormulaRow - 2) & ")"
    .Cells.Font.Size = 10
    .Rows(1).Font.Bold = True
    .UsedRange.EntireColumn.AutoFit

    .range("H:J").NumberFormat = "0.00%;[Red]0.00%"
    End With
oXL.Visible = True

Set oWS = Nothing
Set oWB = Nothing
Set oXL = Nothing
End Sub

----------------------------------

Thanks Seamus

Answer : Formatting on Excel Output from Access

Hi,

you can add in the With statement, like the snippet below

cheers, teylyn
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
With oWS
    FormulaRow = .Cells(.Rows.Count, "d").End(-4162).Row + 2 'xlUp
    .range("c" & FormulaRow & ":f" & FormulaRow).Formula = "=SUM(c2:c" & (FormulaRow - 2) & ")"
    .Cells.Font.Size = 10
    .Rows(1).Font.Bold = True
    .UsedRange.EntireColumn.AutoFit

    .range("H:J").NumberFormat = "0.00%;[Red]0.00%"
    .range("C:F").NumberFormat = "#,##0.00;[Red]#,##0.00"
    End With
Random Solutions  
 
programming4us programming4us