XL VBA adding new worksheet if current worksheet is not empty
Lance,
See if the following makes sense. It does work...
'-------------------------------------------------------------
'Jim Cone August 26, 2004
Sub AddNewSheetIfNeeded()
'Call function to check for any data in active sheet
If Not GetBottomRow = 0 Then
Application.ScreenUpdating = False
'If necessary, add new sheet before the current sheet.
Worksheets.Add befo=ActiveSheet, Count:=1
On Error Resume Next
'Name the sheet
ActiveSheet.Name = " Lance Did It"
On Error GoTo 0
Application.ScreenUpdating = True
End If
End Sub
'========================================
' GetBottomRow() Function
' Called by AddNewSheetIfNeeded.
' Returns the number of the last worksheet row with data.
' Returns 0 if the sheet is blank.
'========================================
Private Function GetBottomRow() As Long
On Error GoTo NoRow
'Search the entire sheet for any data ("*" is a wildcard)
GetBottomRow = Cells.Find(what:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Exit Function
NoRow:
GetBottomRow = 0
End Function
'-------------------------------------------------
Regards,
Jim Cone
San Francisco, CA
"Lance Hoffmeyer" wrote in message ...
I wish to create some code that will create a new
worksheet if the current worksheet is not empty.
Is this an easy thing to do? I don't have a clue
where to start.
Lance
|