0

如何修改此代码以使用多个列?例子:

Sub demo()
  Dim RaFound As Range
  Set RaFound = Rows(1).Find("cost", , , xlPart, , xlNext)
  If Not RaFound Is Nothing Then
    RaFound.EntireColumn.NumberFormat = "#,##0.00 _€"
  End If
End Sub

我还想格式化“价格”和“数量”等列。这段代码应该如何修改?

非常感谢谁能帮忙

4

1 回答 1

3

见下文。单词可以从工作表中获取Range("A1:C5")或硬编码在数组中:

Dim RaFound As Range
Dim words() As Variant
Dim word As Variant

words = Array("cost", "price", "quantity")

For Each word In words

    Set RaFound = Rows(1).Find(word, , , xlPart, , xlNext)

    If Not RaFound Is Nothing Then
        RaFound.EntireColumn.NumberFormat = "#,##0.00 _€"
    End If

Next word
于 2012-12-18T15:13:44.053 回答