boller4prez
02-05-2009, 12:04 PM
I have created some excel vba code. I have data that may be in multiple cells of two sheets. It should go through all the cells comparing each indivdually trying to find data that matches with column A on sheet 2.
But it fails with error 400.
attach included
code:
Sub test()
Set s = Sheets("Sheet1")
Set r = Sheets("Sheet2")
Dim i
Dim j
i = 2
j = 2
s.Range("K1") = r.Range("G1")
s.Range("L1") = r.Range("H1")
s.Range("M1") = r.Range("I1")
s.Range("N1") = r.Range("J1")
s.Range("O1") = r.Range("K1")
Do Until s.Range("D" & i) = ""
If r.Range("A" & j) = s.Range("D" & i) Then
s.Range("K" & i) = r.Range("G" & j)
s.Range("L" & i) = r.Range("H" & j)
s.Range("M" & i) = r.Range("I" & j)
s.Range("N" & i) = r.Range("J" & j)
s.Range("O" & i) = r.Range("K" & j)
i = i + 1
Else
j = j + 1
End If
Loop
End Sub
But it fails with error 400.
attach included
code:
Sub test()
Set s = Sheets("Sheet1")
Set r = Sheets("Sheet2")
Dim i
Dim j
i = 2
j = 2
s.Range("K1") = r.Range("G1")
s.Range("L1") = r.Range("H1")
s.Range("M1") = r.Range("I1")
s.Range("N1") = r.Range("J1")
s.Range("O1") = r.Range("K1")
Do Until s.Range("D" & i) = ""
If r.Range("A" & j) = s.Range("D" & i) Then
s.Range("K" & i) = r.Range("G" & j)
s.Range("L" & i) = r.Range("H" & j)
s.Range("M" & i) = r.Range("I" & j)
s.Range("N" & i) = r.Range("J" & j)
s.Range("O" & i) = r.Range("K" & j)
i = i + 1
Else
j = j + 1
End If
Loop
End Sub