I am trying to write code to switch to the second worksheet if there is one and if there isn't a worksheet I would like to add a new sheet. Is this possible?
I am trying to write code to switch to the second worksheet if there is one and if there isn't a worksheet I would like to add a new sheet. Is this possible?
[VBA]Sub AddSheet()
On Error GoTo NewSheet
Sheets(2).Activate
Exit Sub
NewSheet:
Sheets.Add
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Similar to Malcolms, just showing another way to do it:[vba]Sub SheetAdd2()
If Sheets.Count = 1 Then Sheets.Add
Sheets(2).Activate
End Sub[/vba]Matt