In this article, I listed some code snippets that I generally use in Excel VBA macros. These might be my own or found elsewhere. They might be too simple, and copy-pasting might not work. There might be faster and more logical alternatives…
Assigning the page to a variable;
Dim s As Worksheet
Set s = Sheets("xxx")
Last column number;
sc = s.Cells(1, Columns.Count + 1).End(xlToLeft).Column 'last column
Last row number;
sr = s.Cells(Rows.Count + 1, 1).End(xlUp).Row 'last row
Copy the worksheet to the end of the workbook;
First, assign the worksheet to be copied to the variable “t”. Then, do copy. Then, assign the copied worksheet to the variable “t.
Set t = ActiveSheet
t.Copy After:=Sheets(ActiveWorkbook.Sheets.Count)
Set t = Sheets(ActiveWorkbook.Sheets.Count)
To speed up the macro;
start:
clc = Application.Calculation
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'
'
'
'
finish:
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = clc
Comments