I have a workbook with 35 worksheets, and when a button is clicked, I need a formula to be placed in cell D40 of only worksheets 4-33. The sheet names will change often, so I have to reference the sheets using the code number, and not there name.
I attempted to create the vba code, but I am rusty, and I know I was making up qualifiers that do not work.
Initially, I was going to just code each worksheet separately, but I knew I could do it with a loop. I have commented out how I was initially going to approach this.
My attempt (this is the portion of the code dealing with the loop):
I attempted to create the vba code, but I am rusty, and I know I was making up qualifiers that do not work.
Initially, I was going to just code each worksheet separately, but I knew I could do it with a loop. I have commented out how I was initially going to approach this.
My attempt (this is the portion of the code dealing with the loop):
Code:
Dim ws As Worksheet, i As Integer
For i = 4 To 33
Set ws = Sheet(i)
ws.Range("D40").Select 'this line doesn't work because I made that up :D
ActiveCell.FormulaR1C1 = "='Weekly Setup'!R2C2"
Next i
'Sheet4.Range("D40").Select
'ActiveCell.FormulaR1C1 = "='Weekly Setup'!R2C2"
'Sheet5.Range("D40").Select
'ActiveCell.FormulaR1C1 = "='Weekly Setup'!R2C2"
'keep going with each sheet up to 33