2012-12-18 78 views
0

如何修改此代碼以使用多個列? 例如:Codehelp VBA宏

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 

我想格式化還列,如「價格」和「數量」過。 這段代碼應該如何修改?

非常感謝誰能幫助

回答

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 
+0

那就是它;)謝謝 –