Compile error no line highlighted

2019-07-23 15:49发布

I am getting a compile error: expected expression. No line is highlighted XD

Sub name()

Dim arr() As String
Dim lastRow As Long
c = 2

With ActiveSheet

    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

    For i = 1 To lastRow

        arr = Split(.Cells(i, 1), " ")

        For Each e In arr
            .Cells(i, c).Value = arr(e)
            c = c + 1
        Next

        Set arr = Empty

    Next

End With

End Sub

1条回答
仙女界的扛把子
2楼-- · 2019-07-23 16:21

As @gtwebb stated the name was the main issue.

There were a couple other minor thing I found will debugging:

Sub name2()

Dim e As Variant
Dim lastRow As Long
Dim c As Integer
Dim arr() As String
c = 2

With ActiveSheet

    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

    For i = 1 To lastRow
        c = 2
        arr = Split(.Cells(i, 1), " ")

        For Each e In arr
            .Cells(i, c).Value = e
            c = c + 1
        Next

    Next

End With

End Sub

enter image description here

查看更多
登录 后发表回答