VBA VLOOKUP with multiple sheets and columns

dilshod_k

Board Regular
Joined
Feb 13, 2018
Messages
79
Hello everyone,

I'm having difficulties with understanding how VLOOKUP function works.
To simplify - I have one workbook with two sheets Sheet1 (Columns A (Stocks Sybol), B (Number of Stocks), C (Price)) and Sheet2 (Columns A (Stocks Symbol), D (Number of Stocks), E (Currency)) .
The aim is to find Stock symbol from Column A Sheet2 in the Column A of Sheet1 and corresponding "Number of Stocks" and "Price" values in Columns B and C of Sheet1 should be pasted into Columns D and E (correspondingly) of Sheet2.
I found on internet vba code (as it follows below) to transfer single value from single column at a time but couldn't make it work either.
Please find image files of the sheets below as an attachment.

Sub Shares_Info()

Dim Sheet1Ws As Worksheet

Dim Sheet2Ws As Worksheet

Dim Sheet1LastRow As Long

Dim Sheet2LasRow As Long

Dim x As Long

Dim dataRng As Range

Set Sheet1Ws = ThisWorkbook.Worksheets("Sheet1")

Set Sheet2Ws = ThisWorkbook.Worksheets("Sheet2")

Sheet1LastRow = Sheet1Ws.Range("A" & Rows.Count).End(xlUp)

Sheet2LastRow = Sheet2Ws.Range("A" & Rows.Count).End(xlUp)

Set dataRng = Sheet2Ws.Range("D:E" & Sheet2LastRow)

For x = 2 To Sheet1LastRow

On Error Resume Next

Sheet1Ws.Range("D" & x).Value = Application.WorksheetFunction.VLookup( _

Sheet2Ws.Range("A" & x).Value, dataRng, 4, False)

Next x

End Sub
 

Attachments

  • Sheet1.PNG
    Sheet1.PNG
    26.2 KB · Views: 6
  • Sheet2.PNG
    Sheet2.PNG
    27.9 KB · Views: 6

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Please disregard my message "VBA VLOOKUP with multiple sheets and columns" as the problem has been solved. Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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