excel - 编译错误没有突出显示的行

标签 excel vba

我收到一个编译错误:预期的表达式。没有突出显示的行 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

最佳答案

正如@gtwebb 所说,名称是主要问题。

我发现还有一些其他的小事情会调试:

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

关于excel - 编译错误没有突出显示的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36756773/

相关文章:

excel - 如何在 MAC 上使用 VBA 从 Excel 16 打开工作簿?

excel - 在 "insert function"提示中禁用 excel UDF 计算

vba - 排序组合框 VBA

python - dbf 到 xls - 第一个非标题行未写入

vba - 将范围放入数组以获得更有效的循环

excel - 在 VBA 中使用 Excel 的内置 "My Table has Headers"功能

python - 从 Python : macros may be disabled 运行 VBA 代码

vba - Excel VBA - 数据透视表筛选器运行时错误 '1004' 数据透视项

vba - Excel VBA 英镑和冒号的含义?

Excel 自动填充字母和数字