Samanthad2007
New Member
- Joined
- Aug 12, 2020
- Messages
- 2
- Office Version
- 2016
- 2013
- Platform
- Windows
I have a workbook that calculates three different things for each quarter (so 3 calculations for Q1, 3 for Q2, etc.). The formulas are currently stored in the first row of each quarter and when new data is pasted in each quarter, the macro autofills the formulas down for the current quarter only. I got this to work, but I only have the code set up through Q4 2022 so once it is 2023, I will need to edit the code manually (example below shows the Q3 code with the 3 calculations in columns BX, BY, BZ). How can I create a macro that will work for years on end? I've tried creating a drop down menu, where the user selects the current year and current quarter, but that only works for as long as I set up the code for. I hope this makes sense!
Public Sub Q3_2020()
Application.ScreenUpdating = False
'Q3 2020
With Sheets("Data 1")
.Range("BX2").AutoFill .Range("BX2:BX" & .Cells(Sheets("Data 1").Rows.Count, "A").End(xlUp).Row)
.Range("BY2").AutoFill .Range("BY2:BY" & .Cells(Sheets("Data 1").Rows.Count, "A").End(xlUp).Row)
.Range("BZ2").AutoFill .Range("BZ2:BZ" & .Cells(Sheets("Data 1").Rows.Count, "A").End(xlUp).Row)
End With
'Q3 2020
With Sheets("Data 2")
.Range("BX2").AutoFill .Range("BX2:BX" & .Cells(Sheets("Data 2").Rows.Count, "A").End(xlUp).Row)
.Range("BY2").AutoFill .Range("BY2:BY" & .Cells(Sheets("Data 2").Rows.Count, "A").End(xlUp).Row)
.Range("BZ2").AutoFill .Range("BZ2:BZ" & .Cells(Sheets("Data 2").Rows.Count, "A").End(xlUp).Row)
End With
End Sub
Public Sub Q3_2020()
Application.ScreenUpdating = False
'Q3 2020
With Sheets("Data 1")
.Range("BX2").AutoFill .Range("BX2:BX" & .Cells(Sheets("Data 1").Rows.Count, "A").End(xlUp).Row)
.Range("BY2").AutoFill .Range("BY2:BY" & .Cells(Sheets("Data 1").Rows.Count, "A").End(xlUp).Row)
.Range("BZ2").AutoFill .Range("BZ2:BZ" & .Cells(Sheets("Data 1").Rows.Count, "A").End(xlUp).Row)
End With
'Q3 2020
With Sheets("Data 2")
.Range("BX2").AutoFill .Range("BX2:BX" & .Cells(Sheets("Data 2").Rows.Count, "A").End(xlUp).Row)
.Range("BY2").AutoFill .Range("BY2:BY" & .Cells(Sheets("Data 2").Rows.Count, "A").End(xlUp).Row)
.Range("BZ2").AutoFill .Range("BZ2:BZ" & .Cells(Sheets("Data 2").Rows.Count, "A").End(xlUp).Row)
End With
End Sub