Vlookup from other Sheet vba

vikas_newports

Board Regular
Joined
May 26, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
IN VBA , I want to use vlookup from the other sheet within the same workbook but I do not want to use worksheet name (DOVE) in formula
Currently, I am using the below formula and it is working fine

VBA Code:
 Range("C2").Formula = "=VLOOKUP(B2,DOVE!$C$14:$C$1048576,1,0)"
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
What are you going to use, if not the sheet name?
 
Upvote 0
Fluff, i think we can use sheet number, so in my data, the dove sheet is the 2nd sheet ... how can we use it as worksheet(2) or sheets(2)
 
Upvote 0
You are far better off using the sheet name, if somebody moves the sheet then you will look at the wrong sheet.
 
Upvote 0
you are right but I am afraid if the user change the sheet name from Dove to TOVE then again it will be failed while the sheet number will remain same until unless someone deleted the Dove sheet and create new sheet with the name of Dove
 
Upvote 0
The sheet number is just a reference to where the sheet is in the workbook.
It may be the 2nd sheet now, but if somebody moves it to the 3rd sheet, then it will fail.
 
Upvote 0
Another thing, is that the whatever you use to identify the sheet in the code, it will need to be converted to the sheet name for the formula to work.
 
Upvote 0
Screenshot_1.jpg


Fluff, as per the image it is sheet2 while If I move the position of this sheet to last it will remain Sheet2
 
Upvote 0
I think we can use variable in formula ... also I found below but dont know how to use
below is the example code
VBA Code:
vAns = Application.WorksheetFunction.VLookup(activecell.Offset(0,-10), Workbooks(2).Sheets(1).Range("A:A"), 1, False)
 
Upvote 0
What you said here
how can we use it as worksheet(2) or sheets(2)
Has nothing to do with the codename Sheet2

Also the formula you posted is completely different again.
However you refer to the sheet in VBA you still need to convert it to DOVE! for the formula to work in Excel.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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