Find row with matching cell and retrieve values (VBA)

  • Thread starter Thread starter John
  • Start date Start date
J

John

Using VBA, say I am in Sheet1 worksheet. In sheet2 is four columns.
I have a value stored in a variable. I want to find the row that has
the matching value in Sheet2 Column D. Once it finds the row that
matches, copy the values out of that row's A, B, and C cells into
variables. Any help on this would be much appreciated.

Thanks.

JR
 
Dim vVal, vValA, vValB, vValC
vVal = worksheets("Sheet1").Range("A1").Value
res = Application.Match(vVal,Worksheets("Sheet2").Range("D1:D500"),0)
if not iserror(res) then
With Worksheets("Sheet2")
vValA = .range("A1:A500)(res).Value
vValB = .range("B1:B500)(res).Value
vValC = .range("C1:C500)(res).Value
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top