Worksheets(3).Activate
ActiveSheet.ListObjects(ListName).Range.Select 'Listname is a string-variable
Range(ActiveCell.Offset(1), ActiveCell.Offset(-1)).Select
Selection.Delete Shift:=xlUp
Worksheets(2).Activate
MsgBox "Set-creation was canceled.", vbCritical
Can be re-written as:
With Sheets(3)
.Range(.ListObjects(ListName).Range.Offset(1), .ListObjects(ListName).Range.Offset(-1)).Delete xlUp
End With
Sheets(2).Activate
MsgBox "Set-creation was canceled.", vbCritical
You don't need to .Select
anything in excel-vba especially when dealing with a Range
object - all it's properties and methods can be accessed directly.
Instead of:
Range("A1").Select
Selection.Value = "Test"
Consider:
Range("A1").Value = "Test"
This is better coding and in long procedures will run much faster. The other advantage is that you don't have to keep a track of what the Selection
is when debugging or improving the code.