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