I have several macros and functions that are using ActiveSheet.... and want to replace ActiveSheet... with myActiveSheet. But I always get either compile- or runtime errors.
Sub Main()
Dim myActiveSheet As Worksheet
Dim UsedRangeRows As Long
myActiveSheet = createTestSheet("Basis Depot")
UsedRangeRows = myActiveSheet.UsedRange.Rows.Count
...
End Sub
Public Function createTestSheet(Optional myTestSheet As String) As Worksheet
If sheetExists("myTestSheet") Then
Application.DisplayAlerts = False
Sheets("myTestSheet").Delete
Application.DisplayAlerts = True
End If
If Not myTestSheet = Empty Then
Sheets(myTestSheet).Activate
End If
ActiveSheet.Copy After:=ActiveSheet
ActiveSheet.Name = "myTestSheet"
Set createTestSheet = ActiveSheet
End Function
Bookmarks