Excel VBA循环遍历单元格并替换它们的值

And*_*nov 1 excel vba excel-vba excel-2010

我正在尝试构建一个循环遍历一列单元格的宏,并用该国家/地区的名称替换该单元格中的双字母国家/地区代码.但是,当我尝试运行宏时,我得到一个找不到对象的错误.

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
Run Code Online (Sandbox Code Playgroud)

Dic*_*ika 6

Text属性是只读的 - 您无法设置它.分配给Value属性,它应该工作(例如curCell.Value = "Japan")