Does this code help???
Private Sub CommandButton1_Click()
SheetName = ActiveSheet.Name
'check if there is a parenthesis in sheet name
'No parenthesis then version 1
If InStr(SheetName, "(") = 0 Then
BaseName = SheetName
Version = 1
Else
'BaseName is sheet name left of parenthesis
'Use trim to remove space at end of name
BaseName = Trim(Left(SheetName, InStr(SheetName, "(") - 1))
'version is number after parenthis
Version = Mid(SheetName, InStr(SheetName, "(") + 1)
'remove closing parenthisis
Version = Val(Trim(Left(Version, _
InStr(Version, ")") - 1)))
End If
NextSheetName = BaseName & " (" & (Version + 1) & ")"
Worksheets(NextSheetName).Visible = True
Worksheets("family totals").Range("A5").EntireRow.Hidden = False
End Sub
> Oops sorry I guess I wasn't clear enough, I have already created the 4 extra
> sheets. They are hidden until the user clicks the button.
[quoted text clipped - 38 lines]
>
> End Sub
Roxy - 30 May 2008 17:35 GMT
I tried this by deleting everything that I had and copying and pasting yours
in and I got a "Run time error '9' subscript out of range" and when I tried
to debug it it highlighted the following part of the code in yellow:
Worksheets(NextSheetName).Visible = True
Not sure what to do next? All your help is greatly appreciated. I also
tried another way of easeing this problem of mine yesterday by creating a
Table of Contents with Hyperlinks, but the links wouldn't work after I hide
the sheets I didn't want see/use until they had to. So I don't know the best
way to solve my problem i need to do this to 5 other sheets so a grand total
of 30 sheets :(
Thanks again Roxy!
Joel - 30 May 2008 17:47 GMT
The sheetname is not valid. Add a msgbox before the error to see the
problem. My code is working with the active sheet, you may need to make a
slight change to pick a particul sheet. You can try to make one of the Extra
Earned Income Methd 1 sheet active when running the code.
msgbox(NextSheetName)
Worksheets(NextSheetName).Visible = True
> I tried this by deleting everything that I had and copying and pasting yours
> in and I got a "Run time error '9' subscript out of range" and when I tried
[quoted text clipped - 10 lines]
>
> Thanks again Roxy!
Roxy - 30 May 2008 22:33 GMT
Ok I got the msg box to work and was able to activate the proper sheet so now
the code works. But it still only will allow you to click to unhide 1 sheet.
You can't go back and click the button again and get another sheet to
unhide, the msg box just keeps refering to the same one. Any ideas or am I
at a loss and need to just settle for having all of the hidden sheets pop up
when the button is clicked?
Thanks!
This is the main sheet with the button: Earned Income Methd 1
Theses are the ones that are hidden off of it: Extra Earned Income Methd 1
Extra Earned Income Methd 1 (2)
Extra Earned Income Methd 1 (3)
Extra Earned Income Methd 1 (4)
This is how I've changed the code so far:
Private Sub CommandButton1_Click()
ActiveWorkbook.Sheets("Extra Earned Income Methd 1").Activate
SheetName = ActiveSheet.Name
'check if there is a parenthesis in sheet name
'No parenthesis then version 1
If InStr(SheetName, "(") = 0 Then
BaseName = SheetName
Version = 1
Else
'BaseName is sheet name left of parenthesis
'Use trim to remove space at end of name
BaseName = Trim(Left(SheetName, InStr(SheetName, "(") - 1))
'version is number after parenthis
Version = Mid(SheetName, InStr(SheetName, "(") + 1)
'remove closing parenthisis
Version = Val(Trim(Left(Version, _
InStr(Version, ")") - 1)))
End If
NextSheetName = BaseName & " (" & (Version + 1) & ")"
MsgBox (NextSheetName)
Worksheets(NextSheetName).Visible = True
Worksheets("family totals").Range("A5").EntireRow.Hidden = False
End Sub