简体   繁体   English

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

[英]MS Access VBA Format Excel Sheet Column as Currency

In the below code, I need to format column E & F starting with row(3) as a currency. 在下面的代码中,我需要将以行(3)开头的列E&F格式化为货币。 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: 如果您只想格式化2个单元格,那么它就是一行:

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: 如果要格式化第3行下面的所有单元格,并假设这些单元格尚未填充,则可以使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM