HTFC Forums

H.T.F.C.

How To Fix Computers





Go Back   HTFC Forums > Software Newsgroups > Microsoft Office

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-29-2007, 12:34 PM
TeddyBear
 
Posts: n/a
Default 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
Sponsored Links
Fix your Windows Problems - FAST.
FREE Safe Scan Registry Check. Locate & Fix Errors in Minutes!
  #2  
Old 07-29-2007, 12:48 PM
Harlan Grove
 
Posts: n/a
Default Re: How select a Sheet if the Name is stored in a variable

"TeddyBear" <TeddyBear@discussions.microsoft.com> 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
Sponsored Links
Reply


Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select a Wookbook created using a variable TeddyBear Microsoft Office 6 07-30-2007 03:16 AM
spread sheet neil Windows Vista 5 06-29-2007 06:23 AM
Can't see stored procedures in select data source windows tskogstrom Microsoft Office 0 06-27-2007 12:22 PM
Fax cover sheet not required Jane Microsoft Office 5 05-27-2007 03:30 AM
Term Sheet Templates Staublin Microsoft Office 1 05-03-2007 06:15 PM


All times are GMT. The time now is 07:24 PM.


Powered by vBulletin® Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004 - 2007 Web-S-Sense Pty. Ltd. Usenet and forums posts © their respective authors.
Ad Management by RedTyger