Featured Product

how to call in VBA a Worksheets whit variable?

HiVery good and helpFULL site.Thanks.I want to call in VBA my worsheet instead of his nameby a vaiable declared before.So i can change de scriptto certains pages and no to cut and paste the same code for each page??Thank

Posted by alfredo sanchez on December 20, 2001 12:53 AM

HI!

i think you can use this code:

Sub aver()Dim nam As Integernam = 1 'this is the variable you can use to select the sheetWorksheets(nam).ActivateEnd Sub

Posted by walter on December 20, 2001 1:08 AM

Re: how to call in ... Gracias BUT NO'T

EVEN I tried a functionbut not~

Posted by Joe Was on December 20, 2001 10:43 AM

You can reference a named worksheet by its number even if you re-named it. The shet number is the tab order from left to right, but in some cases it may be in creation order. if I whant to pull a sheet by number and not name I test the code with a Display sample to test if I get the sheet I want. Once I know that sheet1 is infact sheet 1 then I code "Worksheets("Sheet1") even if sheet 1 is named "Menu." JSW

Posted by Cressida on December 20, 2001 3:51 PM

Clarification ......

You said "Once I know that sheet1 is infact sheet 1 then I code Worksheets("Sheet1") even if sheet 1 is named "Menu."I think you meant to say Worksheets(1) instead of Worksheets("Sheet1").

Worksheets("Sheet1") specifies the sheet named Sheet1.If Sheet1 were the first sheet,then Worksheets(1) could be used instead of Worksheets("Sheet1").If sheets are moved or added or deleted, the number that refers to a particular sheet can change.

(8 responses) Hi All, I have a set of First Names and Last names in my application in below format. First Names: Last Names: When i am using text to c

Let's Connect

MrExcel.com debuted on November 21, 1998.

MrExcel.com provides examples of Formulas, Functions and Visual Basic procedures
for illustration only, without warranty either expressed or implied, including
but not limited to the implied warranties of merchantability and/or fitness for
a particular purpose. The Formulas, Functions and Visual Basic procedures on this
web site are provided "as is" and we do not guarantee that they can be used in all
situations.
This site contains affiliate links. Any affiliate commissions that we
earn when you click a link to Amazon or other sites is reinvested in keeping MrExcel.com
running. You can earn a commission for sales leads that you send to us by joining our
affiliate program.
View my Privacy Policy and Terms of Use.