ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Switching between spreadsheets (https://www.excelbanter.com/excel-programming/319295-switching-between-spreadsheets.html)

solomon_monkey

Switching between spreadsheets
 
Final thing today...

I want to switch between worksheets in a macro, however, they will be
called slightly different things each time... each week it will be +1
last week... e.g. 'Week1Worksheet' will next week be
'Week2Worksheet' etc. (The number is the only thing that will be
different the text will be constant)- Is there a way to select the
sheet I want so I can switch between?
Help on this would be SO much appreciated.

Thanks

Solomon


Nick Shinkins[_2_]

Switching between spreadsheets
 
Using code that actually selects sheets is best avoided since it considerably
slows down execution.

However,

If you define a variable such as

Dim WeekNum as integer

then

Sheets("Week" & WeekNum & "Worksheet").Select

will have the effect you desire.

A loop of some kind may be useful to you using WeekNum as the index.

Nick Shinkins






"solomon_monkey" wrote:

Final thing today...

I want to switch between worksheets in a macro, however, they will be
called slightly different things each time... each week it will be +1
last week... e.g. 'Week1Worksheet' will next week be
'Week2Worksheet' etc. (The number is the only thing that will be
different the text will be constant)- Is there a way to select the
sheet I want so I can switch between?
Help on this would be SO much appreciated.

Thanks

Solomon



Tom Ogilvy

Switching between spreadsheets
 
If lastweek is the activesheet and the new sheet is the next in tab order:

Dim sh as Worksheet, sh1 as Worksheet
set sh = Activesheet
set sh1 = Activesheet.Next
msgbox sh.Name & " " & sh1.Name
Sh1.Range("A1").Value = sh.range("A1").Value


--
Regards,
Tom Ogilvy


"solomon_monkey" wrote in message
oups.com...
Final thing today...

I want to switch between worksheets in a macro, however, they will be
called slightly different things each time... each week it will be +1
last week... e.g. 'Week1Worksheet' will next week be
'Week2Worksheet' etc. (The number is the only thing that will be
different the text will be constant)- Is there a way to select the
sheet I want so I can switch between?
Help on this would be SO much appreciated.

Thanks

Solomon





All times are GMT +1. The time now is 11:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com