I am trying to utlize the recording feature to learn about the code that controls excel via taking an action and then reviewing the code that is recorded.
Recently I was able to get the following code to work:
Sheets("GEN INCENTIVE").Select
Range("AV1").Select
Columns("AV:AV").Select
Selection.Insert Shift:=xlToRight
Range("AV2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/100"
Range("AV2").Select
Selection.Copy
Range("AV2:AV268").Select
ActiveSheet.Paste
Selection.Style = "Percent"
Selection.Copy
Range("AU2").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.Style = "Percent"
I was concerned that the bolded text would prevent the code from being executed if a new data sheet was used that had more than 267 rows, I wanted the selection to go all the way down to the end of the data hop right and then copy and paste that formula across that range.
The advice I got was to name my worksheets with something like this:
Dim GenIncentive As Worksheet
Set GenWS = Worksheet("GEN INCENTIVE")
What exactly does this do in terms of the code listed above, do I need to reference GenWS every time there is a line? What is the point of esatlbishing those variables.
Recently I was able to get the following code to work:
Sheets("GEN INCENTIVE").Select
Range("AV1").Select
Columns("AV:AV").Select
Selection.Insert Shift:=xlToRight
Range("AV2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]/100"
Range("AV2").Select
Selection.Copy
Range("AV2:AV268").Select
ActiveSheet.Paste
Selection.Style = "Percent"
Selection.Copy
Range("AU2").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.Style = "Percent"
I was concerned that the bolded text would prevent the code from being executed if a new data sheet was used that had more than 267 rows, I wanted the selection to go all the way down to the end of the data hop right and then copy and paste that formula across that range.
The advice I got was to name my worksheets with something like this:
Dim GenIncentive As Worksheet
Set GenWS = Worksheet("GEN INCENTIVE")
What exactly does this do in terms of the code listed above, do I need to reference GenWS every time there is a line? What is the point of esatlbishing those variables.