Desired results is to read from the criteria tab |
Find the corresponding match in the Data tab |
And write the results in the Dest Tab |
My problem is my VB script is only writing one value and not all of them. |
Application.ScreenUpdating = False
Set wsData = Sheets("Data")
Set wsCriteria = Sheets("Criteria")
Set wsDest = Sheets("Dest")
lr = wsCriteria.Cells(Rows.Count, "A").End(xlUp).Row
Set rng = wsCriteria.Range("A2:A" & lr)
If wsData.FilterMode Then wsData.ShowAllData
For Each cell In rng
With wsData.Range("A1").CurrentRegion
.AutoFilter field:=1, Criteria1:=cell.Value
wsData.Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Copy wsDest.Range("A1")
wsDest.UsedRange.Columns.AutoFit
End With
Next cell
wsData.AutoFilterMode = False
wsData.Activate
Application.ScreenUpdating = True
End Sub
Data Tab
name | age | city | state | zip | cell | desk |
Bob | 20 | Jackson | NY | 12345 | 123 | 234 |
ZZZXCarol | 21 | Hazard | KY | 12346 | 123 | 234 |
Danielle | 22 | London | TN | 12347 | 123 | 234 |
Steve | 23 | Pineville | Mi | 12348 | 123 | 234 |
123Jen456 | 24 | Somerset | WY | 12349 | 123 | 234 |
Naresh | 25 | Manchester | PA | 12350 | 123 | 234 |
Ron | 26 | Monticello | VA | 12351 | 123 | 234 |
Sam XXX | 27 | Albany | UT | 12352 | 123 | 234 |
Vinny | 28 | Morehead | AL | 12353 | 123 | 234 |
Criteria TAB
name |
Bob |
Carol |
Danielle |
Steve |
Jen |
Naresh |
Ron |
Sam |
Vinny |
Dest TAB
name | age | city | state | zip | cell | desk |
Vinny | 28 | Morehead | AL | 12353 | 123 | 234 |