Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
So the following code:
Public Sub addSheet() Sheets.Add After:=Sheets(Sheets.Count) Range("A6").Select End Sub It works just fine when it is in a module. Adds the sheet and selects cell A6. But when it is in the code attached to another worksheet, it adds the sheet then gives a 1004 error. It would seem that the code attached to one sheet cannot select a cell on another sheet. I have just spent a frustrating several hours trying to figure out why I was getting this error. Some days I feel very naïve. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
So the following code:
Public Sub addSheet() Sheets.Add After:=Sheets(Sheets.Count) Range("A6").Select End Sub It works just fine when it is in a module. Adds the sheet and selects cell A6. But when it is in the code attached to another worksheet, it adds the sheet then gives a 1004 error. It would seem that the code attached to one sheet cannot select a cell on another sheet. I have just spent a frustrating several hours trying to figure out why I was getting this error. Some days I feel very naïve. I use this... Sub InsertSheet() 'Ctrl+Shift+I ' Inserts a new sheet before the active sheet Dim iCount% iCount = InputBox("Enter the number of sheets to insert", "Insert Sheets", 1) ActiveWorkbook.Sheets.Add Befo=ActiveSheet, Count:=iCount End Sub ...which could easily be modified for the insert position... -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
puppetsock presented the following explanation :
So the following code: Public Sub addSheet() Sheets.Add After:=Sheets(Sheets.Count) Range("A6").Select End Sub [...] Put that code in a Module and call it from anywhere. Bruno |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Toolbar Gone - STUPID STUPID STUPID!! | Excel Programming | |||
Toolbar Gone - STUPID STUPID STUPID!! | Excel Programming | |||
Toolbar Gone - STUPID STUPID STUPID!! | Excel Programming | |||
Sources of Excel Tips, Tricks & Code | Excel Discussion (Misc queries) | |||
Excel TIPS&TRICKS and Samples | Excel Discussion (Misc queries) |