JohnGow383
Board Regular
- Joined
- Jul 6, 2021
- Messages
- 141
- Office Version
- 2013
- Platform
- Windows
Hi, I need help with the following.
I have a table in Sheet1 and a data table in Sheet2.
I want the 2nd column C of Table 1 to populate from the value of the adjacent cell in column B by looking up the master table in Sheet2, column T to read value in column U
I realize this can easily be done using the Vlookup formula but would prefer a VBA solution.
I will then have the macro fired from a worksheet change event using the range B2:B22 in sheet 2. So any change in that column will re-calculate Column C.
Here is the code I have but it doesn't work so any help will be appreciated.
I have a table in Sheet1 and a data table in Sheet2.
I want the 2nd column C of Table 1 to populate from the value of the adjacent cell in column B by looking up the master table in Sheet2, column T to read value in column U
I realize this can easily be done using the Vlookup formula but would prefer a VBA solution.
I will then have the macro fired from a worksheet change event using the range B2:B22 in sheet 2. So any change in that column will re-calculate Column C.
Here is the code I have but it doesn't work so any help will be appreciated.
VBA Code:
Sub PlayLookUp()
Dim PlayGest As String
Dim PlayList As Range
Dim LoopList, Pokemon As Range
Dim lrT As Long
Set ws1 = Sheet1
Set ws2 = Sheet2
Set LoopList = ws1.Range("B2:B22")
lrT = ws2.Cells(Rows.Count, "T").End(xlUp).Row
Set PlayList = ws2.Range(ws2.Cells(4, "T"), ws2.Cells(lrT, "U"))
For Each Pokemon In LoopList
PlayGest = Application.WorksheetFunction.VLookup(Pokemon.Value, PlayList, 2, False)
Pokemon.Offset(0, 1).Value = PlayGest
Next Pokemon
End Sub