I'm new to VBA and need help writing a macro given the following
A. Enddate = .Cell(lRow, 7).Value.
B. AnnualDepr = .Cell(lRow, 11).Value.
C. PartialYearDepr = (.Cell(lRow, 11).Value) /12) * (DateDiff("m", EndDate, FY)).
D. FY or Input Range = range of fiscal year end dates (i.e. 10/31/13 - 10/31/75), Range(Cells(2, 14), Cells(2, lColumn)).
E. Output range = Range(Cells(lRow, 14), Cells(lRow, lColumn)).
Here's the set-up:
If the "Year(EndDate) > Year(FY)" then copy AnnualDepr to the appropriate cells in Output Range.
ElseIf "Year(EndDate) = Year(FY)" then use PartialYearDepr in the appropriate cell in Output Range.
Else Place 0 in the remaining cells in Output Range.
It's important that "AnnualDepr" and "PartialYearDepr" appear beneath the correct FY, and I can't seem to get that right (i.e. linking the Input Range (i.e. Range(Cells(2, 14), Cells(2, lColumn))) and Output Range (i.e. Range(Cells(lRow, 14), Cells(lRow, lColumn))).
I've tried looping with 'For Each', but once the first argument is satisfied (i.e. Year(EndDate) > Year(FY)), AnnualDepr is copied across the entire Output Range, INSTEAD of only copying up to the cell where Year(EndDate) = Year(FY) occurs.
PartialYearDepr should only appear when Year(EndDate) = Year(FY) occurs.
After both arguments are satisfied (i.e. Year(End Date) > = Year(FY)), 0 should appear in the Output Range until the last column (i.e. lColumn).
Thanks in advance for any help.
Bookmarks