Vlook up function in Macro

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,281
Office Version
  1. 2013
Platform
  1. Windows
Code:
Dim ws As Worksheet, rngFind As Range
Set ws = ThisWorkbook.Sheets("0600")
Set rngFind = ws.Range("b:b").Find(what:=Sheets("Result").Range("A5").Value, MatchCase:=True)
If Not rngFind Is Nothing Then
Sheets("Result").Range("b5").Value = rngFind.Offset(0, 1).Value
Sheets("Result").Range("c5").Value = rngFind.Offset(0, 2).Value
End If

Good Day,
Im trying to change the above code as given code below but im not good enough to make it!

Code:
Dim ws As Worksheet, rngFind As Range
Set ws = ThisWorkbook.Sheets("0600")
Set rngFind = ws.Range("b:b").Find(what:=Sheets("Result").Range("A5:A24").Value, MatchCase:=True)
If Not rngFind Is Nothing Then
Sheets("Result").Range("b5:d24").Value = rngFind.Offset(0, 3).Value
Sheets("Result").Range("c5:e24").Value = rngFind.Offset(0, 4).Value
End If

I just wanted make it easier due to instead of writing them all one by one!
Could somebody help me on this problem?
Many Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Range("A5:A24").Value doesn't make sense -- try entering =A5:A24 in a cell -- you'll either get #VALUE! or the intersection of A5:A24 and the cell you enter it into (if you enter =A4:A24 in cell F22, you'll see the value of A22 there.)
You don't have to do this one by 1, you could put it in a loop, something like:

Sub try()
Dim ws As Worksheet, rngFind As Range
Set ws = ThisWorkbook.Sheets("0600")
For i = 5 To 24
Set rngFind = ws.Range("B:B").Find(what:=Sheets("Result").Range("B" & i).Value, MatchCase:=True)
If Not rngFind Is Nothing Then
Sheets("Result").Range("B" & i).Value = rngFind.Offset(0, 1).Value
Sheets("Result").Range("C" & i).Value = rngFind.Offset(0, 2).Value
End If
Next
End Sub
 
Upvote 0
Range("A5:A24").Value doesn't make sense -- try entering =A5:A24 in a cell -- you'll either get #VALUE! or the intersection of A5:A24 and the cell you enter it into (if you enter =A4:A24 in cell F22, you'll see the value of A22 there.)
You don't have to do this one by 1, you could put it in a loop, something like:

Sub try()
Dim ws As Worksheet, rngFind As Range
Set ws = ThisWorkbook.Sheets("0600")
For i = 5 To 24
Set rngFind = ws.Range("B:B").Find(what:=Sheets("Result").Range("B" & i).Value, MatchCase:=True)
If Not rngFind Is Nothing Then
Sheets("Result").Range("B" & i).Value = rngFind.Offset(0, 1).Value
Sheets("Result").Range("C" & i).Value = rngFind.Offset(0, 2).Value
End If
Next
End Sub

Bob,
How can i add a code to get the sum values of cells 5/24 into the cell 25?
 
Upvote 0

Forum statistics

Threads
1,217,757
Messages
6,138,429
Members
450,137
Latest member
HANHAN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top