Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Subscript out of range (Error 9)


Hi folks
I have a macro run for a form combo box, all works OK

I wish to use at vb combo box, have placed my code inside to run on
change .
All runs, I copy my template spreadsheet and go to rename it based on
the date selected from my combo box, the rename fails, error 9

Sdate = Format(cmbDate.Value, "dd mm")

' append name of sheet based on choice of day or night roster
If Sheets("menu").optDay.Value = True Then ' Day Roster
' Day roster
Sname = Sdate & "-D"
Else
' night roster
Sname = Sdate & "-N"
End If

' check if sheet by that name exists, if false proceed
If SheetExists(Sname) = False Then
Sheets("Menu").Select
If Sheets("menu").optDay.Value = True Then ' if Day Roster,
copy day roster template
Sheets("Template").Visible = True
Sheets("Template").Select
Sheets("Template").Copy Befo=Sheets(2)
Sheets("Template (2)").Select <= Error 9 HERE
Sheets("Template (2)").Name = Sname

I think I have a hint of the problem, is it the () characters?
Any fix possible?

thanks
John
Images of home (NZ)
http://www.titahi-bay.co.nz/home
What we are up to in the UK
http://www.titahi-bay.co.nz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Subscript out of range (Error 9)

The new sheet (copy) will be the activesheet, so you don't need to select
it. You can refer to it as the activesheet

Sdate = Format(cmbDate.Value, "dd mm")

' append name of sheet based on choice of day or night roster
If Sheets("menu").optDay.Value = True Then ' Day Roster
' Day roster
Sname = Sdate & "-D"
Else
' night roster
Sname = Sdate & "-N"
End If

' check if sheet by that name exists, if false proceed
If SheetExists(Sname) = False Then
Sheets("Menu").Select
If Sheets("menu").optDay.Value = True Then ' if Day Roster,
Sheets("Template").Visible = True
Sheets("Template").Select
Sheets("Template").Copy Befo=Sheets(2)
Activesheet.Name = Sname

--
Regards,
Tom Ogilvy


"John in Surrey" wrote in message
...

Hi folks
I have a macro run for a form combo box, all works OK

I wish to use at vb combo box, have placed my code inside to run on
change .
All runs, I copy my template spreadsheet and go to rename it based on
the date selected from my combo box, the rename fails, error 9

Sdate = Format(cmbDate.Value, "dd mm")

' append name of sheet based on choice of day or night roster
If Sheets("menu").optDay.Value = True Then ' Day Roster
' Day roster
Sname = Sdate & "-D"
Else
' night roster
Sname = Sdate & "-N"
End If

' check if sheet by that name exists, if false proceed
If SheetExists(Sname) = False Then
Sheets("Menu").Select
If Sheets("menu").optDay.Value = True Then ' if Day Roster,
copy day roster template
Sheets("Template").Visible = True
Sheets("Template").Select
Sheets("Template").Copy Befo=Sheets(2)
Sheets("Template (2)").Select <= Error 9 HERE
Sheets("Template (2)").Name = Sname

I think I have a hint of the problem, is it the () characters?
Any fix possible?

thanks
John
Images of home (NZ)
http://www.titahi-bay.co.nz/home
What we are up to in the UK
http://www.titahi-bay.co.nz



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
Subscript out of range error Vishal[_3_] Excel Programming 3 January 4th 06 11:14 PM
Subscript out of range error moglione1 Excel Discussion (Misc queries) 2 August 30th 05 01:21 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
subscript out of range error Darren Excel Programming 3 November 24th 04 03:38 PM
Subscript out of range error enz[_2_] Excel Programming 3 May 26th 04 02:20 PM


All times are GMT +1. The time now is 12:02 AM.

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

About Us

"It's about Microsoft Excel"