【发布时间】:2013-02-08 08:56:01
【问题描述】:
如果列名中有单词 COST,则使用 excel 宏将列格式更改为货币。
如果列名称是 - “最终成本”或“总成本”或“项目成本” 然后将列格式更改为货币。
谢谢
【问题讨论】:
标签: excel ms-office excel-formula office-2007 vba
如果列名中有单词 COST,则使用 excel 宏将列格式更改为货币。
如果列名称是 - “最终成本”或“总成本”或“项目成本” 然后将列格式更改为货币。
谢谢
【问题讨论】:
标签: excel ms-office excel-formula office-2007 vba
您可以使用Conditional Formatting 执行此操作,无需宏。
突出显示表格左列中的一个单元格。
在功能区的Home 部分,单击Conditional Formatting,然后单击New Rule。
Use a formula to determine which cells to format.
输入此公式。如果您的行标题不是从 A1 开始,请相应更改:=SEARCH("cost",A$1,1)
点击Format并将Number设置为Currency,然后点击确定。
在Conditional Formatting Rules Manager 中,设置Applies to 使其覆盖您的桌子。
【讨论】:
试试类似的东西
Public Sub FormatCostColumnsAsCurrency()
Dim sht As Worksheet
Set sht = ActiveSheet
Dim rng As Range
Dim i As Integer
For i = 1 To sht.UsedRange.Columns.Count
Set rng = sht.Cells(1, i)
If InStr(LCase(rng.Text), "cost") > 0 Then
sht.Columns(i).NumberFormat = "$#,##0.00"
End If
Next
End Sub
【讨论】:
试试下面的代码
Sub CurrFormat()
Dim colHeader As Range
Set colHeader = Range("A1:E1")
Dim currCell As Range
Set currCell = Cells.Find("COST")
If Not currCell Is Nothing Then currCell.NumberFormat = "$#,##0.00"
End Sub
【讨论】: