I’m trying to learn VBA.
I have a sheet with 50 rows. Eventually, the sheet will have more rows, week by week.
In my macro, I want to select all of the rows and columns whenever the macro runs.
When I recorded the macro and selected all of them, I got this code:
Sheets(“Main”).Select
Range(“B1”).Select
Selection.AutoFilter
ActiveSheet.Range(“$A$1:$BN$50”).AutoFilter Field:=2, Criteria1:= _
“Dorado Hills”
Range(“$A$1:$BN$50”).Select
Range(“B1”).Activate
Selection.Copy
Sheets(“Dorado Hills”).Select
ActiveSheet.Unprotect Password:=”whatever”
Range(“A1”).Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range(“A1″).Select
ActiveSheet.Protect Password:=”whatever”
The objective is to turn on filtering, select all of the rows, filter based on a name (in this case “Dorado Hills”) and copy the filtered results.
Move to another sheet and paste them.
But, if the 50 is in the macro, what will happen the next time when there are 80 rows?
And, if the columns go beyond BN?
Won’t I be missing the additional/new rows?