【发布时间】:2022-01-22 23:14:51
【问题描述】:
我正在尝试使用 VBA 编辑我的 excel 表,但编译时出现错误。它不识别第 2 行和第 10 行。
Sub IfThenElse()
Dim i As Integer = 23
While Not IsNull(Cells(i, 35).Value)
If Cells(i, 35).Value > 1E+16 Then
Cells(i, 4).Value = Cells(i, 35).Value / 10
Else
Cells(i, 4).Value = Cells(i, 35).Value
i = i + 1
End If
End While
End Sub
【问题讨论】:
-
Dim i As Integer = 23也不是有效的语法。声明,然后赋值。 -
这个
While...End While是无效的语法,你需要使用Do While...Loop(见Do...Loop statement)。 -
或find the last row 并使用
For...Next循环。 -
@BigBen 只是为了记录,“最后使用的单元格”与“第一个空白单元格”不同(OP 现在所做的)。所以结果可能会有所不同。
标签: excel vba compiler-errors