Apr 04 2023 09:24 PM
I want to create a macro which checks if values of year 2018 is greater than 2017 and then checks if values of 2019 were greater than 2018 and so on. For 2027, if i enter any value it should similarly compare it with the 2026. The maximum it can go is till 2030 which makes it in a range of 13 rows. However, the code will be assigned to the a button which will prompt a message.
Apr 05 2023 02:09 AM
Sub comparison()
Dim i, j As Long
Range("C:C").Clear
j = Range("A" & Rows.Count).End(xlUp).Row
For i = 3 To j
If Cells(i, 2).Value > Cells(i - 1, 2).Value Then
Cells(i, 3).Value = "increase in comparison to year " & Cells(i - 1, 1)
Else
End If
Next i
End Sub
Maybe with these lines of code. In the attached file you can click the button in cell G2 to run the macro.