2

如果这是一个简单的问题,我深表歉意,我昨天才开始宏编程,自从 qBasic(或任何语言一段时间)以来就没有用 BASIC 编写过。我试图读取变量是否等于特定值,如果是,则将另一个单元格写入电子表格(如果它包含数据)。我不断收到没有 for 的 next 错误。如果没有第一个 if 语句,它运行良好,有人可以帮助我吗?如果您可以帮助编写价值而不是内容,那么您将获得奖励,但我可以在不打扰您的情况下弄清楚这一点。感谢您帮助我走到这一步,这个网站非常宝贵。您可能会认出一些编码。

子 B920LOI()

x = 5 iMaxRow = 3000

对于 iRow = 3 到 iMaxRow

If Sheets("Sheet2").Cells(iRow, "B") = "B920" Or Sheets("Sheet2").Cells(iRow, "B") = " B920" Then



    If Sheets("Sheet2").Cells(iRow, "K") > 35 And Sheets("Sheet2").Cells(iRow, "K") < 55 Then

    ' Check that cell is not empty.
    ' Copy the cell to the destination
    With Worksheets("Sheet2").Cells(iRow, "K")
    .Copy Destination:=Worksheets("920 LOI").Cells(x, "B")

    End With

    x = x + 1


    Else
        'Nothing in this cell.
        'Do nothing.

    End If

Else
        'Nothing in this cell.
        'Do nothing.

End If

下一个 iRow

结束子

这是“工作版”谢谢。

4

1 回答 1

7

您的巢必须匹配......“结束于”需要位于 If 块内 With 所在的位置。

于 2013-11-04T01:05:01.270 回答