MS Access VBA格式Excel工作表列作为货币

时间:2011-08-22 19:51:22

标签: excel ms-access vba

在下面的代码中,我需要格式化列E& F以行(3)作为货币开头。谢谢!

            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

2 个答案:

答案 0 :(得分:9)

Range("E:F").NumberFormat = "$#,##0.00"

Range("E:F").SpecialCells(xlCellTypeFormulas).NumberFormat = "$#,##0.00"

Range("E:F").SpecialCells(xlCellTypeConstants).NumberFormat = "$#,##0.00"

答案 1 :(得分:1)

如果你只想格式化2个单元格,那就是一行:

wb.Sheets(1).Range("E3:F3").NumberFormat = "$#,##0.00"

如果要格式化第3行下方的所有单元格,并假设尚未填充这些单元格,则可以使用:

Range("E3:F3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "$#,##0.00"
相关问题