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

Hi,

I'm trying to create a button that when a month is selected (using a
drop-down box) and the button is clicked it either

a) if the sheet currently exists - goes to the chosen tab OR

b) if the sheet does not exist - creates a copy of the master sheet and
renames it the chosen month.

I've got so near with the following coding its just something letting me
down, but i don't know what. Please help

If Worksheets(Format(Cells("10", "B"), "mmmm yy")).Visible Then

'Goto
ActiveWorkbook.Worksheets(Format(Cells("10", "B"), "mmmm yy")).Activate

Else

'create
ActiveWorkbook.Worksheets("MASTER").Copy After:=Worksheets("MENU")
ActiveSheet.Name = Format(Cells("10", "B"), "mmmm yy")
Worksheets(Format(Cells("10", "B"), "mmmm yy")).Range("Y1") =
Format(Worksheets("Menu").Range("B10"), "mmmm yyyy")


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Creating or going to a worksheet

Let me know where it 'fails', I might have some ideas. For example, you
can't create the sheet, you can't change the name, you can't set the value,
etc.

"sdg8481" wrote in message
...
Hi,

I'm trying to create a button that when a month is selected (using a
drop-down box) and the button is clicked it either

a) if the sheet currently exists - goes to the chosen tab OR

b) if the sheet does not exist - creates a copy of the master sheet and
renames it the chosen month.

I've got so near with the following coding its just something letting me
down, but i don't know what. Please help

If Worksheets(Format(Cells("10", "B"), "mmmm yy")).Visible Then

'Goto
ActiveWorkbook.Worksheets(Format(Cells("10", "B"), "mmmm yy")).Activate

Else

'create
ActiveWorkbook.Worksheets("MASTER").Copy After:=Worksheets("MENU")
ActiveSheet.Name = Format(Cells("10", "B"), "mmmm yy")
Worksheets(Format(Cells("10", "B"), "mmmm yy")).Range("Y1") =
Format(Worksheets("Menu").Range("B10"), "mmmm yyyy")




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating or going to a worksheet

Dim s as String, sh as Worksheet
s = Format(Cells("10", "B"), "mmmm yy")
on Error Resume Next
set sh = Worksheets(s)
On error goto 0
if sh is nothing then
worksheets("Master").Copy After:=Worksheets(Worksheets.count))
Else
sh.Activate
End if


--
Regards,
Tom Ogilvy


"sdg8481" wrote in message
...
Hi,

I'm trying to create a button that when a month is selected (using a
drop-down box) and the button is clicked it either

a) if the sheet currently exists - goes to the chosen tab OR

b) if the sheet does not exist - creates a copy of the master sheet and
renames it the chosen month.

I've got so near with the following coding its just something letting me
down, but i don't know what. Please help

If Worksheets(Format(Cells("10", "B"), "mmmm yy")).Visible Then

'Goto
ActiveWorkbook.Worksheets(Format(Cells("10", "B"), "mmmm

yy")).Activate

Else

'create
ActiveWorkbook.Worksheets("MASTER").Copy After:=Worksheets("MENU")
ActiveSheet.Name = Format(Cells("10", "B"), "mmmm yy")
Worksheets(Format(Cells("10", "B"), "mmmm yy")).Range("Y1") =
Format(Worksheets("Menu").Range("B10"), "mmmm yyyy")




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Creating or going to a worksheet

Hi,

It seems to faile when creating a new sheet, as it finds an existing
sheetperfectly well, but if the sheet does exist it comes up with "Run-time
Error '9': Subscript out of range"

and the if statement appears to be the problem

Thanks

"Terry Aney" wrote:

Let me know where it 'fails', I might have some ideas. For example, you
can't create the sheet, you can't change the name, you can't set the value,
etc.

"sdg8481" wrote in message
...
Hi,

I'm trying to create a button that when a month is selected (using a
drop-down box) and the button is clicked it either

a) if the sheet currently exists - goes to the chosen tab OR

b) if the sheet does not exist - creates a copy of the master sheet and
renames it the chosen month.

I've got so near with the following coding its just something letting me
down, but i don't know what. Please help

If Worksheets(Format(Cells("10", "B"), "mmmm yy")).Visible Then

'Goto
ActiveWorkbook.Worksheets(Format(Cells("10", "B"), "mmmm yy")).Activate

Else

'create
ActiveWorkbook.Worksheets("MASTER").Copy After:=Worksheets("MENU")
ActiveSheet.Name = Format(Cells("10", "B"), "mmmm yy")
Worksheets(Format(Cells("10", "B"), "mmmm yy")).Range("Y1") =
Format(Worksheets("Menu").Range("B10"), "mmmm yyyy")





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
Creating a Worksheet zephyr Excel Discussion (Misc queries) 2 September 11th 06 07:25 AM
Creating a dynamic Worksheet name? CRayF Excel Programming 13 September 23rd 05 12:33 PM
Creating a new worksheet? schoujar[_6_] Excel Programming 2 August 31st 05 07:43 AM
Creating a Worksheet in VBA Jako[_13_] Excel Programming 1 June 8th 04 11:09 PM
Creating a new worksheet from another Sheeny[_13_] Excel Programming 2 May 25th 04 06:14 PM


All times are GMT +1. The time now is 02:03 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"