DougiePh
New Member
- Joined
- Jan 22, 2019
- Messages
- 20
I have a named range "TAB" (B8:K26) in several worksheets of a work book. I am a retired want IT professional, new to VBA, and view the range like a file with the rows as records and columns as fields. I want to loop through the rows examining column D checking for an exact match to a value I supply. I then want to pass back the value in column J of the row to the worksheet. I have looked at many sites for the answer but none seem to have what I need. I know this can be done with VLOOKUP, however, I am currently doing this with the entire range and don't want to define another range that is a portion of the larger range. I have tried several FOR EACH scenarios but always get a VALUE error. I'm not sure what I am doing wrong or missing.
For Each n In WorkSheet(SheetName).Range("Tab")
if Worksheet(SheetName).Range("Tab").ColumnD = MyValue
Then
GetValue = WorkSheet(SheetName).Range("Tab").CilumnJ
END IF
NEXT n
I know the above doesn't work but shows what I am trying to do.
I am passing the SheetName and MyValue to the function GetValue.
For Each n In WorkSheet(SheetName).Range("Tab")
if Worksheet(SheetName).Range("Tab").ColumnD = MyValue
Then
GetValue = WorkSheet(SheetName).Range("Tab").CilumnJ
END IF
NEXT n
I know the above doesn't work but shows what I am trying to do.
I am passing the SheetName and MyValue to the function GetValue.