我正在嘗試構建一個循環遍歷單元格列的宏,並將該單元格中的兩個字母國家代碼替換爲該國家/地區的名稱。但是,當我嘗試運行宏時,我得到一個對象未找到錯誤。Excel VBA循環遍歷單元格並替換它們的值
Sub ChangeCountryText()
'
' ChangeCountryText Macro
' Changes country codes
'
For counter = 2 To 20
Set curCell = ActiveSheet.Cells(counter, 1)
Select Case curCell.Text
Case "JP"
curCell.Text = "Japan"
Case "FR"
curCell.Text = "France"
Case "IT"
curCell.Text = "Italy"
Case "US"
curCell.Text = "United States"
Case "NL"
curCell.Text = "Netherlands"
Case "CH"
curCell.Text = "Switzerland"
Case "CA"
curCell.Text = "Canada"
Case "CN"
curCell.Text = "China"
Case "IN"
curCell.Text = "India"
Case "SG"
curCell.Text = "Singapore"
End Select
Next counter
End Sub
你沒有找到對象?當我測試時,curCell.Text引起了一個問題,可以通過使用curCell.Value來糾正。此代碼也區分大小寫。 – Fionnuala 2010-11-09 23:12:16
是的,實施該更改可解決問題。感謝您的建議。 – 2010-11-11 18:55:06