2016-07-20 128 views
0

我的宏有问题,请执行Microsoft Excel。我想创建一个宏来检查在一行中是否有单词表示它与用户在单元格中输入的单词相同,而不是检查整行以比较其他信息。在前。用户输入亚当斯密12.05.2016和宏必须在姓名列中找到名称亚当,并检查此亚当是否具有姓史密斯和日期12.05.2016。如果是打印整行。 我已经创建了整个宏,但是我得到了error1004应用程序定义或对象定义的错误。Visual Basic宏错误

Sub Test() 
Dim r As Integer 
Dim c1 As Integer 
Dim c2 As Integer 
Dim i As Integer 
r = 0 
c1 = 0 
c2 = 0 
i = 0 
' Iterates through name column 
Do Until Cells(r, c1).Value = "" 
    ' If program finds the name in name row equal to name in (6, G) returns true 
     If Cells(r, c1).Value = Cells(6, G).Value Then 
      ' Iterates through surname row 
      Do Until Cells(r, c2).Value = "" 
       ' If surname is the same and date is on the right of the surname Return tur 
       If Cells(r, c2).Value = Cells(6, H).Value And Cells(r, c2 + 1).Value = Cells(6, i) Then 
        Do Until i <= 0 
        ' Output whole data from the row 
        Cells(10, H + i).Value = Cells(r, c1 + i).Value 
        i = i + 1 
        Loop 
       End If 
      c2 = c2 + 1 
      Loop 
     End If 
r = r + 1 
Loop 
End Sub 
+0

由于行和列零不存在,您的变量不能以值0开头。从1开始。另外,你不能写'Cells(6,G)'列被称为A为1,B为2等。 –

+0

你可以用公式来做到这一点,是否需要VBA? –

+0

@Nathan_Sav我是总新手,如果我们谈论Excel。 :( – Trefl

回答