Sub或函数未在VBA中为excel定义

时间:2014-08-11 18:37:02

标签: vba

当我尝试运行模块时,某些正文可以帮助我解释下面代码返回“sub或function not defined”的原因。

Sub Tokenize()
    Dim txt As String
    Dim i As Integer
    Dim FullName As Variant

    For Counter = 1 To 300
        Set curCell = Worksheet("Sheet1").Cells(Counter, 1)
        txt = curCell.Value
        FullName = Split(txt, " ")
        For i = 0 To UBound(FullName)
            Cells(Counter, i + 1).Value = FullName(i)
        Next i

    Next Counter

End Sub

1 个答案:

答案 0 :(得分:3)

我怀疑错误在这一行:

Set curCell = Worksheet("Sheet1").Cells(Counter, 1)
                      ^^^

您应该将Worksheet替换为Worksheets(请注意其他s)。