在执行do while函数的同时在编码中键入不匹配

时间:2019-04-09 20:31:52

标签: excel vba

我的代码类型不匹配,但是我不知道问题出在哪里。 我认为这与返工工作表有关,但我不确定。难道我做错了什么?我是excel vba的新手,所以我不知道

Sub ending_test()

Z = 3
Do While Not IsEmpty(Worksheets("Raw Data").Cells(Z, 2))
  y = 4
  Do While Not IsEmpty(Worksheets("Rework").Cells(y, 1))
    If Worksheets("Raw Data").Cells(Z, 2) = Worksheets("Rework").Cells(y, 3) And
       Worksheets("Raw Data").Cells(Z, 3) = Worksheets("Rework").Cells(y, 4) And
       Worksheets("Raw Data").Cells(Z, 4) = Worksheets("Rework").Cells(y, 6) 
    Then
      Worksheets("Rework").Cells(y, 12).ClearContents
      Worksheets("Rework").Cells(y, 12) = Worksheets("Raw data").Cells(2, 7)
    End If
    y = y + 1
  Loop

  Z = Z + 1
Loop
End Sub

1 个答案:

答案 0 :(得分:0)

每当将命令拆分为单独的行时,都必须在该行的en处使用“ _”来表示它。不知道这是什么导致错误...

对于您的if语句,它看起来像

If Worksheets("Raw Data").Cells(Z, 2) = Worksheets("Rework").Cells(y, 3) _
And Worksheets("Raw Data").Cells(Z, 3) = Worksheets("Rework").Cells(y, 4) _
And Worksheets("Raw Data").Cells(Z, 4) = Worksheets("Rework").Cells(y, 6) _
Then

如果您提供示例数据,那就太好了。