2016-07-20 10 views
0

私は自分のマクロdo Microsoft Excelに問題があります。私は、ある行に、ユーザーがセルに入力した単語と同じ単語があり、他の情報を比較するために行全体をチェックする必要があるかどうかを確認するマクロを作成します。例:ユーザーはAdam Smith 12.05.2016を入力し、マクロはname列にAdamという名前を見つけ、Adamの名前がSmithで日付が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で開始できません。また、「セル(6、G)」列はAの数値1、Bの数値2などと呼ばれることはできません。 –

+0

これを式で行うことができます.VBAは必要ですか? –

+0

@Nathan_Sav Excelについて話しているなら、私は初心者です。 :( – Trefl

答えて

1

あなたは配列数式、通常の式でこれを行うが、ENTERあなたはCTRLシフトに必要なので、多くの細胞に働き、それが私の最初の本

=MAX(IF(CONCATENATE($I$1:$I$3," ",$J$1:$J$3)=L1,ROW($I$1:$I$3)))

になりますことができます名前は、これが発生した行番号を与え、I、J、最後に名前とL1でのデータ入力にあった、そして、あなたが値を取得するためにINDEXを使用することができ、またはOFFSET

https://support.office.com/en-gb/article/INDEX-function-a5dcf0dd-996d-40a4-a822-b56b061328bd