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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7152802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:48:22  来源:igfitidea点击:

MS Access VBA Format Excel Sheet Column as Currency

excelms-accessvba

提问by Bruno

In the below code, I need to format column E & F starting with row(3) as a currency. Thanks!

在下面的代码中,我需要将列 E & F 以 row(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

回答by Patrick Honorez

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

or

或者

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

or

或者

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

回答by PaulStock

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"