Searching in 2nd sheet for values in first
Closed
Toff
-
Nov 11, 2011 at 02:33 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Nov 14, 2011 at 09:27 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Nov 14, 2011 at 09:27 AM
Related:
- Searching in 2nd sheet for values in first
- Sheet right to left in google sheet - Guide
- Mark sheet in excel - Guide
- Windows network commands cheat sheet - Guide
- Based on the values in cells b77 b81 ✓ - Excel Forum
- Google searching in another country - Guide
1 response
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Nov 14, 2011 at 09:27 AM
Nov 14, 2011 at 09:27 AM
Hi Toff,
Try this code:
Sub test()
Dim lRow As Integer
Dim x As Integer
Dim y As Integer
lRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
y = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Sheets("Sheet1").Range("A1:A" & lRow)
x = 1
Do
If cell.Value = Sheets("Sheet2").Range("A" & x).Value Then
Sheets("Sheet2").Range("B" & x).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
x = x + 1
Loop Until x > y
Next
End Sub
Hopefully I understood you correctly.
It's always best to provide a small example of how your sheet looks like and how you would like your sheet to look like after the code.
Best regards,
Trowa
Try this code:
Sub test()
Dim lRow As Integer
Dim x As Integer
Dim y As Integer
lRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
y = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Sheets("Sheet1").Range("A1:A" & lRow)
x = 1
Do
If cell.Value = Sheets("Sheet2").Range("A" & x).Value Then
Sheets("Sheet2").Range("B" & x).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
x = x + 1
Loop Until x > y
Next
End Sub
Hopefully I understood you correctly.
It's always best to provide a small example of how your sheet looks like and how you would like your sheet to look like after the code.
Best regards,
Trowa