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

Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Selecting a worksheet based on the sheet Number

Your code is good. Does Sheet40 exist???
--
Gary''s Student - gsnu200819


"QuietMan" wrote:

Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Selecting a worksheet based on the sheet Number


this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Selecting a worksheet based on the sheet Number

Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Selecting a worksheet based on the sheet Number

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Selecting a worksheet based on the sheet Number


Olny issue is there are about 150 sheets in this file and I have to format
each sets of sheets differently when I print them. That why I was using the
case select so i couls range the numbers of sheet for each distinct formatting

Thanks, but looks like there is osmething about this file that causing the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Selecting a worksheet based on the sheet Number


how about something like this then?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long

For i = 1 To Worksheets.Count
Select Case i

Case 1, 3

Worksheets(i).PageSetup.CenterFooter = "Page &P of &N"
Case 2
Worksheets(i).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Olny issue is there are about 150 sheets in this file and I have to format
each sets of sheets differently when I print them. That why I was using the
case select so i couls range the numbers of sheet for each distinct formatting

Thanks, but looks like there is osmething about this file that causing the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Selecting a worksheet based on the sheet Number


Thanks...I give this a try
Hopefully I doesn't reference the sheet position

Thanks for the help
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about something like this then?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long

For i = 1 To Worksheets.Count
Select Case i

Case 1, 3

Worksheets(i).PageSetup.CenterFooter = "Page &P of &N"
Case 2
Worksheets(i).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Olny issue is there are about 150 sheets in this file and I have to format
each sets of sheets differently when I print them. That why I was using the
case select so i couls range the numbers of sheet for each distinct formatting

Thanks, but looks like there is osmething about this file that causing the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Selecting a worksheet based on the sheet Number

Sorry It did not work as it select bases on relatively position of the sheet
rhtner that sheet number
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about something like this then?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long

For i = 1 To Worksheets.Count
Select Case i

Case 1, 3

Worksheets(i).PageSetup.CenterFooter = "Page &P of &N"
Case 2
Worksheets(i).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Olny issue is there are about 150 sheets in this file and I have to format
each sets of sheets differently when I print them. That why I was using the
case select so i couls range the numbers of sheet for each distinct formatting

Thanks, but looks like there is osmething about this file that causing the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing









  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Selecting a worksheet based on the sheet Number

well, i have no idea whether you're using the sheet index number, sheet name or
the sheet codename.

--


Gary

"QuietMan" wrote in message
...
Sorry It did not work as it select bases on relatively position of the sheet
rhtner that sheet number
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about something like this then?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long

For i = 1 To Worksheets.Count
Select Case i

Case 1, 3

Worksheets(i).PageSetup.CenterFooter = "Page &P of &N"
Case 2
Worksheets(i).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Olny issue is there are about 150 sheets in this file and I have to format
each sets of sheets differently when I print them. That why I was using the
case select so i couls range the numbers of sheet for each distinct
formatting

Thanks, but looks like there is osmething about this file that causing the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing













  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Selecting a worksheet based on the sheet Number

I'm using the sheet codename...

Thanks again
--
Helping Is always a good thing


"Gary Keramidas" wrote:

well, i have no idea whether you're using the sheet index number, sheet name or
the sheet codename.

--


Gary

"QuietMan" wrote in message
...
Sorry It did not work as it select bases on relatively position of the sheet
rhtner that sheet number
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about something like this then?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long

For i = 1 To Worksheets.Count
Select Case i

Case 1, 3

Worksheets(i).PageSetup.CenterFooter = "Page &P of &N"
Case 2
Worksheets(i).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Olny issue is there are about 150 sheets in this file and I have to format
each sets of sheets differently when I print them. That why I was using the
case select so i couls range the numbers of sheet for each distinct
formatting

Thanks, but looks like there is osmething about this file that causing the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing












  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Selecting a worksheet based on the sheet Number

not sure if this will help you or not:

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long
Dim Sht_Select As Variant
For i = 1 To Worksheets.Count
On Error Resume Next
Sht_Select = ThisWorkbook.VBProject _
.VBComponents("Sheet" & i).Properties("Name").Value
On Error GoTo 0
Select Case i
Case 1, 3
Sheets(Sht_Select).PageSetup.RightFooter = "Page &P of &N"
Case 2
Sheets(Sht_Select).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
I'm using the sheet codename...

Thanks again
--
Helping Is always a good thing


"Gary Keramidas" wrote:

well, i have no idea whether you're using the sheet index number, sheet name
or
the sheet codename.

--


Gary

"QuietMan" wrote in message
...
Sorry It did not work as it select bases on relatively position of the
sheet
rhtner that sheet number
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about something like this then?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim i As Long

For i = 1 To Worksheets.Count
Select Case i

Case 1, 3

Worksheets(i).PageSetup.CenterFooter = "Page &P of &N"
Case 2
Worksheets(i).PageSetup.LeftFooter = "Page &P of &N"
End Select
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Olny issue is there are about 150 sheets in this file and I have to
format
each sets of sheets differently when I print them. That why I was using
the
case select so i couls range the numbers of sheet for each distinct
formatting

Thanks, but looks like there is osmething about this file that causing
the
macro not to work, because it works fine in a blank workbook
--
Helping Is always a good thing


"Gary Keramidas" wrote:

how about this?

Sub PrepSystemWide()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.PageSetup.CenterFooter = "Page &P of &N"
Next
Sheet3.Select
Application.ScreenUpdating = True
End Sub


--


Gary

"QuietMan" wrote in message
...
Here is a sample the code Im working with...for some reason it will
not
work....
Sub PrepSystemWide()
Application.ScreenUpdating = False
For X = 1 To 3
Select Case X
Case Is = 1: TTK = 40
Case Is = 2: TTK = 125
Case Is = 3: TTK = 127
End Select
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"
Next X
Sheet3.Select
Application.ScreenUpdating = True
End Sub
--
Helping Is always a good thing


"Gary Keramidas" wrote:

this worked for me

Sub test()
Dim TTK As String
Dim Sht_Select As String
TTK = 2
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select
End Sub

--


Gary

"QuietMan" wrote in message
...
Can anyone tell me why the code does not work

TTK = 40
Sht_Select = "Sheet" & TTK
Sheets(Sht_Select).Select

Thanks

--
Helping Is always a good thing














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
Rename Worksheet without Selecting the sheet Don Guillett Excel Programming 0 December 12th 06 06:48 PM
Rename Worksheet without Selecting the sheet [email protected] Excel Programming 0 December 12th 06 06:38 PM
Selecting sheets based on cell in each sheet Steve Excel Programming 2 August 4th 06 07:48 PM
Selecting a number of rows based on the content matpj[_25_] Excel Programming 3 November 25th 05 09:27 AM
Selecting a sheet based on a cell wilcster Excel Programming 3 December 30th 04 05:05 PM


All times are GMT +1. The time now is 10:20 PM.

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"