宏VBA脚本

时间:2014-03-10 03:35:40

标签: debugging excel-vba visual-c++ vba excel

有人可以帮我解决这个问题。我有这个代码,但它不起作用。有些东西是错的,它说“Sub或Function not defined”。

Sub Macro1()
'
' Macro1 Macro
'
Dim x As Integer, result As String

x = 2

' 1st row

Do While Cells(x, 4).Value = 1

      If Cells(x, 3).Value <= Cells(x, 2).Value And Not Cells(x, 4).Value < Cells(x, 1).Value Then
      result = "pass"

      Else
      result = "fail"

      End If
      Cell(x, 5).Value = result

      x = x + 1
Loop

End Sub

1 个答案:

答案 0 :(得分:0)

Cell更改为Cells,它会起作用。 Excel只是对该错误消息没有足够的帮助。但是,当您打开编辑器并尝试运行它时,它会为Cell选择文本。

Sub Macro1()
'
' Macro1 Macro
'
Dim x As Integer, result As String

x = 2

' 1st row

Do While Cells(x, 4).Value = 1

      If Cells(x, 3).Value <= Cells(x, 2).Value And Not Cells(x, 4).Value < Cells(x, 1).Value Then
      result = "pass"

      Else
      result = "fail"

      End If

      Cells(x, 5).Value = result

      x = x + 1
Loop

End Sub