MS Access VBA Format Excel Sheet Column as Currency
In the below 开发者_JAVA技巧code, I need to format column E & F starting with row(3) as a currency. Thanks!
Set objApp = CreateObject("Excel.Application")
objApp.Visible = True
Set wb = objApp.Workbooks.Open("template.xls", True, False)
wb.Sheets(1).Rows(3).Delete
wb.Sheets(1).Range("A1").Value = title
'need to format column E & F as currency
Set objApp = Nothing
Range("E:F").NumberFormat = "$#,##0.00"
or
Range("E:F").SpecialCells(xlCellTypeFormulas).NumberFormat = "$#,##0.00"
or
Range("E:F").SpecialCells(xlCellTypeConstants).NumberFormat = "$#,##0.00"
If you only want to format 2 cells, it's one line:
wb.Sheets(1).Range("E3:F3").NumberFormat = "$#,##0.00"
If you want to format all cells below row 3, and assuming those cells aren't already populated, then you could use:
Range("E3:F3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "$#,##0.00"
精彩评论