I'm relatively new to VBA, I have only some experience with Python and only very little experience looking at other VBA macros and adjusting them to my need, so I'm trying to do what I can.
What I am trying to do is for each part number pasted in worksheet B (worksheet B, row A) I want to find the same part number from a different worksheet containing all part numbers (worksheet D, row A) and copy the description (worksheet D, row H) from worksheet D to another column, (worksheet B, row D) then check the next part number in the row and repeat.
The current error that I'm getting is that there is "Compile error: Else without if", I'm sorry that I am not very proficient, but any help would be greatly appreciated.
Other information:
-My part numbers to search through in worksheet B, column B are filled in from worksheet A, is it okay to just make it =A!B2 or =CONCATENATE(A!B2)?
Sub Description()
Dim wsA As Worksheet, wsB As Worksheet, wsC As Worksheet, wsD As Worksheet
Dim Rng As Range
Set wsB = Worksheets("B")
Set wsD = Worksheets("D")
Do: aRow = 2
If wsB.Cells(aRow, 2) <> "" Then
With Worksheets("D").Range("A:A")
x = wsB.Cells(aRow, 2)
Set Rng = .Find(What:=x, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Selection.Copy
wsB.Cells(dRow, 2).Paste
dRow = dRow + 1
Else
aRow = aRow + 1
Loop Until wsB.Cells(aRow, 2) = ""
End Sub
Thanks again!
Edit: Can't Execute code in break mode is current error
Sub Description()
Dim wsA As Worksheet, wsB As Worksheet, wsC As Worksheet, wsD As Worksheet
Dim Rng As Range
Set wsB = Worksheets("B")
Set wsD = Worksheets("D")
aRow = 2
dRow = 2
Do:
If wsB.Cells(aRow, 1) <> "" Then
With Worksheets("D").Range("A:A")
Set Rng = .Find(What:=wsB.Cells(aRow, 1), _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Rng.Copy
Rng.Offset(0, 3).Paste (Cells(aRow, 4))
dRow = dRow + 1
aRow = aRow + 1
End With
End If
Loop Until wsB.Cells(aRow, 1) = ""
End Sub