how to write vlookup in vba code

monu

New Member
Joined
Jun 21, 2011
Messages
11
I have a sheet with several column- stocks name,future price, spot price etc.
How to use vlookup function the data stocks and its future price in seperate sheet.
Exp:
Stocks spotprice future price

icici 232 256
idbi 58 62
....
....
...
 
Hi

There are a thousand out there some of them for free. Just tap in Something like "Excel VBA Free Books" into a search engine. Otherwise I think you could try "Excel VBA Programming for Dummies" it's as good a place as any to start.

regards

Kev
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi Mono

Add thisto your existing code after "Next fcomp". I have assumed that you will want to place the information on a third sheet.

Code:
'*** Order Table by Future Price
  Sheets("sheet2").Activate
  
  Sheets("sheet2").Range("A1:D200").Select
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("B2:B9"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet2").Sort
        .SetRange Range("A1:D9")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
'*** Copy & Paste range for top 5 from sheet2tp sheet3
Sheets("sheet2").Range("a1:B6").Copy
Sheets("sheet3").Activate
Sheets("sheet3").Range("a1").Select
ActiveSheet.Paste

regards

Kev
 
Upvote 0
thanks kev,
result is coming but giving rum time error.
actualy result sould be only 5 top stock and its future value.
 
Upvote 0
OK

Remove the code I asked you to insert. And put it under another command button, and run seperatly. we can see if this is cousing the prob. Make sure you have created a third sheet.

regards

Kev
 
Upvote 0

Forum statistics

Threads
1,224,621
Messages
6,179,936
Members
452,949
Latest member
beartooth91

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