0

如果列名中有单词 COST,则使用 excel 的宏将列格式更改为货币。

就像列名是 - “最终成本”或“总成本”或“项目成本”,然后将列格式更改为货币。

谢谢

4

3 回答 3

3

尝试类似的东西

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
于 2013-02-22T17:32:44.007 回答
0

Try below code

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
于 2013-02-22T17:41:47.043 回答
0

您可以使用 来执行此操作Conditional Formatting,不需要宏。

  1. 突出显示表格左列中的一个单元格。

  2. Home功能区部分,单击Conditional Formatting,然后单击New Rule

  3. Use a formula to determine which cells to format.

  4. 输入这个公式。如果您的行标题不是从 A1 开始,请相应更改:=SEARCH("cost",A$1,1)

  5. 单击Format并设置NumberCurrency,然后单击确定。

  6. Conditional Formatting Rules Manager, 中设置Applies to,使其覆盖您的桌子。

于 2013-02-22T17:30:33.423 回答