studentlearner
New Member
- Joined
- Oct 7, 2021
- Messages
- 30
- Office Version
- 365
- Platform
- Windows
So currently I got multiple guys name john in my excel, how do I ensure that my vba doesn't go through the same cell over and over again?
this the code I'm working with
So currently it only calls upon and loop only on the first one only. How do I make it go through all john instead of it just locating one john?
this the code I'm working with
VBA Code:
Sub match_Data()
Dim rSH As Worksheet
Dim sSh As Worksheet
Set rSH = ThisWorkbook.Sheets("Master")
Set sSh = ThisWorkbook.Sheets("Schedule")
Dim fName As String, lName As String
For a = 2 To sSh.Range("A" & Rows.Count).End(xlUp).Row
fName = sSh.Range("B" & a).Value
For b = 2 To rSH.Range("A" & Rows.Count).End(xlUp).Row
If rSH.Range("B" & b).Value = fName Then
sSh.Range("A" & a).Value = rSH.Range("A" & b).Value
sSh.Range("B" & a).Value = rSH.Range("B" & b).Value
sSh.Range("C" & a).Value = rSH.Range("C" & b).Value
Exit For
End If
Next b
Next a
Debug.Print "Completed"
End Sub
So currently it only calls upon and loop only on the first one only. How do I make it go through all john instead of it just locating one john?
Code ID | Name | Schedule |
1010 | John | AM |
1011 | John | PM |
1033 | Mick | AM |