Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Running code when a worksheet opens
I have built some code asking the user how many worksheets he would like to
add to a workbook with 1 visible worksheet. It is attached to a button and I now need to put that code in a property such as "On Open" (I'm better with Access), so when the worksheet opens, the first question is "How many...". I've read some of the other posts, but can't find the property/ies they refer to. So far, I have: ------------------------------------ Private Sub Worksheet_Open() Dim NumSheets, x, y y = Worksheets.Count NumSheets = InputBox("How many sheets to add?") If NumSheets = Empty Then End Else For x = 1 To NumSheets Sheets("1").Select Sheets("1").Copy After:=Sheets(1) y = y + 1 ActiveSheet.Name = y - 2 Next x End If End Sub ------------------------------------ The reason I have "y - 2" above is because I also have 2 hidden worksheets (used for data validation). If not "Private Sub Worksheet_Open()", then where? Thanks in advance for any help. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Running Code on Hidden Worksheet | Excel Programming | |||
Refer to the worksheet containing the current running code | Excel Programming | |||
how to prevent code running when in a worksheet code | Excel Programming | |||
Running VBA Code not written within the currrent worksheet | Excel Programming | |||
Running Code in an XLA from a Worksheet | Excel Programming |