I am trying to get a range to divide itself by itself divided by a different range, and then multiplied by 12. I wrong the code below in an attempt to achieve this, and keep getting an error stating "Compile error: Object required".
I have tried changing the "AnnualizeMonths" and "AmountsRange" variables from Strings to Ranges, and also get an error.
Does anybody know what I am going wrong? Thanks for the help in advance!
I have tried changing the "AnnualizeMonths" and "AmountsRange" variables from Strings to Ranges, and also get an error.
Does anybody know what I am going wrong? Thanks for the help in advance!
Code:
Sub Annualize()
'Annualizes Amounts Populated Within The Amounts Column ("P") as Dynamic Range
Dim AnalystWorkbook As Workbook
Set AnalystWorkbook = ThisWorkbook
Dim CashFlow As Worksheet
Set CashFlow = AnalystWorkbook.Worksheets("Cash Flow")
Dim StartCell As String
Set StartCell = AnalystWorkbook.CashFlow.Range("P59")
Dim EndCell As Range
Set EndCell = AnalystWorkbook.CashFlow.StartCell.End(xlDown)
Dim AmountsRange As Range
Set AmountsRange = AnalystWorkbook.CashFlow.Range(StartCell, EndCell)
Dim AnnualizeMonths As String
Dim FirstMonthValue As Range
Dim LastMonthValue As Range
Set FirstMonthValue = Range("R59")
Set LastMonthValue = AnalystWorkbook.CashFlow.AmountsColumn.Offset(0, 1)
AnnualizeMonths = AnalystWorkbook.CashFlow.Range(FirstMonthValue, LastMonthValue)
AmountsRange = [IFERROR((AmountsRange/AnnualizeMonths)*12), AmountsRange)]
End Sub