Hi I am guessing there is an easy solution to this, but I have spent hours attempting to locate with no success. My apologies for the code potentially being klunky, as I piece together code over various searches based on my needs. This code is a piece of a much larger macro which is why it is not self-contained with the sub()
The problem: I am trying to create a formula based on a dynamic range (referring to column to left's amount of rows and autofill the formula down. I need this to run over multiple sheets, and the column "AD" I am referring to will change on the amount of rows on each sheet.
This code works fine for the first sheet, but I can't get it to loop through the other worksheets (worksheet names will also change in both name and quantity).
From what I have read, I think I need to "set" the range somehow, but I can't seem to do it. Any ideas? I'll paste my current code below:
The problem: I am trying to create a formula based on a dynamic range (referring to column to left's amount of rows and autofill the formula down. I need this to run over multiple sheets, and the column "AD" I am referring to will change on the amount of rows on each sheet.
This code works fine for the first sheet, but I can't get it to loop through the other worksheets (worksheet names will also change in both name and quantity).
From what I have read, I think I need to "set" the range somehow, but I can't seem to do it. Any ideas? I'll paste my current code below:
Code:
For Each WSD in Worksheets 'Note - WSD is dim'd earlier
'Adding the percentage on all sheets
'Creating the percentage
Range("AE3").Select
'Formatting the word percentage
With Selection.Font
.Name = "Calibri (Theme Body)"
.FontStyle = "Bold"
.Size = 12
End With
ActiveCell.FormulaR1C1 = "Percentage:"
'Choosing the last row available based on adjacent left column
Dim LRAD As Long
LRAD = Range("AD" & Rows.Count).End(xlUp).Row
Range("AE4").Select
ActiveCell.FormulaR1C1 = "=(RC[-1])/(RC[-2])"
Range("AE4").AutoFill Destination:=Range("AE4:AE" & LRAD)
Range("AE4:AE" & LRAD).Copy
ActiveSheet.Range("AE4:AE" & LRAD).PasteSpecial xlPasteValues
Application.CutCopyMode = False
With Selection
.HorizontalAlignment = xlRight
.NumberFormat = "0.0%"
End With
With Selection.Font
.Name = "Calibri (Theme Body)"
.FontStyle = "Bold"
.Size = 12
End With
Next