TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Office

Notices

How select a Sheet if the Name is stored in a variable

Microsoft Office


Reply
 
Thread Tools Display Modes
Old 28-08-2007, 03:55 PM   #1
TeddyBear
Guest
 
Posts: n/a
How select a Sheet if the Name is stored in a variable

In my macro I add sheets programatically based on values held in a variable.

e.g. Sheets.Add.Name = vCurrVendNos

vCurrVendNos is set to values in one of my sheets. I then copy and paste
selected cells/ranges between my sheets. My variable is called vCurrVendNos
an it has a value of "101030".

I am trying to do what this statement achieves. I used this simple statement
to test whether it works and it does.

Sheets("101030").Select.

But the name of the sheets changes and I cannot hard code the value of all
the sheets because it changes based on data within one of the sheets..

My problem is that when I use the following

Sheets(vCurrVendNos).Select
OR Sheets("vCurrVendNos").Select
OR Sheets("vCurrVendNos").Activate

I get my error routine being activated. I know this must be relatively
simple but I can't seem to get the syntax or commands right.

  Reply With Quote
Old 28-08-2007, 03:55 PM   #2
Harlan Grove
Guest
 
Posts: n/a
Re: How select a Sheet if the Name is stored in a variable

"TeddyBear" <> wrote...
>In my macro I add sheets programatically based on values held in a
>variable.


This STILL isn't the appropriate newsgroup in which to ask questions about
macro programming in SPECIFIC applications.

>e.g. Sheets.Add.Name = vCurrVendNos
>
>vCurrVendNos is set to values in one of my sheets. I then copy and paste
>selected cells/ranges between my sheets. My variable is called vCurrVendNos
>an it has a value of "101030".

....

Are you CERTAIN its value is a string rather than a numeric type?

>My problem is that when I use the following
>
>Sheets(vCurrVendNos).Select
>OR Sheets("vCurrVendNos").Select
>OR Sheets("vCurrVendNos").Activate
>
>I get my error routine being activated. I know this must be relatively
>simple but I can't seem to get the syntax or commands right.


The second and third statements above are clear errors. "vCurrVendNos" is a
string constant, and unless you have a worksheet actually named vCurrVendNos
this SHOULD throw a runtime error.

If the first statement above throws a runtime error, it's a near certainty
your vCurrVendNos variable has numeric type. Try

Sheets(CStr(vCurrVendNos)).Select


  Reply With Quote
Old 28-08-2007, 03:55 PM   #3
Harlan Grove
Guest
 
Posts: n/a
Re: How select a Sheet if the Name is stored in a variable

"TeddyBear" <> wrote...
>In my macro I add sheets programatically based on values held in a
>variable.


This STILL isn't the appropriate newsgroup in which to ask questions about
macro programming in SPECIFIC applications.

>e.g. Sheets.Add.Name = vCurrVendNos
>
>vCurrVendNos is set to values in one of my sheets. I then copy and paste
>selected cells/ranges between my sheets. My variable is called vCurrVendNos
>an it has a value of "101030".

....

Are you CERTAIN its value is a string rather than a numeric type?

>My problem is that when I use the following
>
>Sheets(vCurrVendNos).Select
>OR Sheets("vCurrVendNos").Select
>OR Sheets("vCurrVendNos").Activate
>
>I get my error routine being activated. I know this must be relatively
>simple but I can't seem to get the syntax or commands right.


The second and third statements above are clear errors. "vCurrVendNos" is a
string constant, and unless you have a worksheet actually named vCurrVendNos
this SHOULD throw a runtime error.

If the first statement above throws a runtime error, it's a near certainty
your vCurrVendNos variable has numeric type. Try

Sheets(CStr(vCurrVendNos)).Select


  Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to select options from a SELECT control Abhishek Tiwari Internet Explorer 1 28-08-2007 08:42 PM
unable to select options from a SELECT control Abhishek Tiwari Internet Explorer 1 28-08-2007 08:38 PM
Select a Wookbook created using a variable TeddyBear Microsoft Office 12 28-08-2007 03:56 PM
Can't see stored procedures in select data source windows tskogstrom Microsoft Office 0 28-08-2007 02:37 PM
Can't see stored procedures in select data source windows tskogstrom Microsoft Office 0 28-08-2007 02:37 PM


< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 10:13 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional