VBA: IF year < TODAY() replace formula with Value

G MJ

New Member
Joined
Dec 16, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,

I've been trying to figure out a VBA that will remove formulas and replace with the Values calculated if the year is less than current year.

I need the formulas in B8:B13 to change into values if the year in B4 is less than the date in B1. This will also need to be done in the other rows if their year is less than current.

Any Help will be appreciated.

2021
123456
Total Cost202020212022202320242024
£ 150,000.00£2,000£2,000£2,000£2,000£2,000£2,000
£ 17,250.00£690£690£690£690£690£690
£ 3,000.00£120£120£120£120£120£120
£ 9,000.00£360£360£360£360£360£360
£ 9,000.00£360£360£360£360£360£360
£ 9,000.00£360£360£360£360£360£360
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this:
VBA Code:
Sub MyMacro()

    Dim lc As Long
    Dim c As Long
    
    Application.ScreenUpdating = False
    
'   Find last column in row 4 with data
    lc = Cells(4, Columns.Count).End(xlToLeft).Column
    
'   Loop through all columns, starting with column 2 (B)
    For c = 2 To lc
'       Check to see if year in row 4 is less than current year
        If Cells(4, c) < Year(Date) Then
'           Change rows 8:13 to values
            Range(Cells(8, c), Cells(13, c)).Value = Range(Cells(8, c), Cells(13, c)).Value
        End If
    Next c
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
You are welcome.
And welcome to the Board!
:)
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top