Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Selecting a worksheet

I need code to select a specific worksheet. I can not use the name on the
tab since I have code which renames the worksheet based on data input.
Currently if you look at the VBA Project the name is Sheet1(01 Jan 09). It
is the 01 Jan 09 which can change, but the Sheet1 stays consistent. So how
can I select the worksheet based on the Sheet1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Selecting a worksheet

for each ws in worksheets
if ws.codename = "Sheet1" then
ws.activate
exit for
end if
next

untested for typos, apart from that it should work except -

Note when you insert a new sheet it's codename is not updated if the VBE is
closed until the wb is saved, closed & reopened.


Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I need code to select a specific worksheet. I can not use the name on the
tab since I have code which renames the worksheet based on data input.
Currently if you look at the VBA Project the name is Sheet1(01 Jan 09). It
is the 01 Jan 09 which can change, but the Sheet1 stays consistent. So how
can I select the worksheet based on the Sheet1



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Selecting a worksheet

for each ws in worksheets
if ws.codename = "Sheet1" then
ws.activate
exit for
end if
next


No need for all that. If you know the code name of the worksheet you
can use it directly:

Sheet11.Activate ' works regardless of sheet Name and Index

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Sat, 15 Nov 2008 10:08:05 -0000, "Peter T" <peter_t@discussions
wrote:

for each ws in worksheets
if ws.codename = "Sheet1" then
ws.activate
exit for
end if
next

untested for typos, apart from that it should work except -

Note when you insert a new sheet it's codename is not updated if the VBE is
closed until the wb is saved, closed & reopened.


Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I need code to select a specific worksheet. I can not use the name on the
tab since I have code which renames the worksheet based on data input.
Currently if you look at the VBA Project the name is Sheet1(01 Jan 09). It
is the 01 Jan 09 which can change, but the Sheet1 stays consistent. So how
can I select the worksheet based on the Sheet1


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Selecting a worksheet


"Chip Pearson" wrote in message
...
for each ws in worksheets
if ws.codename = "Sheet1" then
ws.activate
exit for
end if
next


No need for all that. If you know the code name of the worksheet you
can use it directly:

Sheet11.Activate ' works regardless of sheet Name and Index


Indeed that works, but I think only if the sheet's codename is name is known
and can be hardcoded at design time and only within the same project (ie
can't reference a sheet that way in some other workbook without a reference)
and there could be compile problems if the sheet is subsequently deleted.

Regards,
Peter T


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Selecting a worksheet


Indeed that works, but I think only if the sheet's codename is name is known
and can be hardcoded at design time


You can use code like the following:


Dim S As String
S = "Sheet3"
ThisWorkbook.VBProject.VBComponents(S).Activate




Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sat, 15 Nov 2008 19:23:01 -0000, "Peter T" <peter_t@discussions
wrote:


"Chip Pearson" wrote in message
.. .
for each ws in worksheets
if ws.codename = "Sheet1" then
ws.activate
exit for
end if
next


No need for all that. If you know the code name of the worksheet you
can use it directly:

Sheet11.Activate ' works regardless of sheet Name and Index


Indeed that works, but I think only if the sheet's codename is name is known
and can be hardcoded at design time and only within the same project (ie
can't reference a sheet that way in some other workbook without a reference)
and there could be compile problems if the sheet is subsequently deleted.

Regards,
Peter T

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a range on another worksheet without selecting the worksheet [email protected] Excel Programming 1 December 21st 06 11:06 PM
Selecting Next Worksheet Fleone Excel Programming 3 May 2nd 06 05:05 PM
selecting a worksheet rocket0612 Excel Worksheet Functions 2 March 1st 06 09:47 AM
selecting cell range in other worksheet without switching to worksheet suzetter[_4_] Excel Programming 4 June 22nd 05 08:55 PM
Selecting Last Worksheet Alex Excel Programming 7 September 26th 04 09:35 PM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"