Macro to change cell text based on expiry date

aidan_cov

New Member
Joined
Feb 8, 2007
Messages
27
I have a basic data list for sales leads and the status of each line is chosen from a drop-down list. I need to write a macro that will automatically change all cells that are "ongoing" to "no" once two months (or 61 days if that is easier) have expired after the original date against that particular line. The dates are in column A and status in column F. The table is in Sheet2 (cells A1:A6). This is quite a large workbook and is currently at row 13781 and increasing by about 15 rows per day. Thank you in advance for any help as I am a complete novice when it comes to VBA.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
try this on a copy of your file.

VBA Code:
Sub do_it()
Application.ScreenUpdating = False

    For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row
        If IsDate(Cells(r, "A")) = True And Cells(r, "A").Value <= Date - 60 And UCase(Cells(r, "F")) = "ONGOING" Then
            Cells(r, "F").Value = "no"
        End If
    Next r
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
try this on a copy of your file.

VBA Code:
Sub do_it()
Application.ScreenUpdating = False

    For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row
        If IsDate(Cells(r, "A")) = True And Cells(r, "A").Value <= Date - 60 And UCase(Cells(r, "F")) = "ONGOING" Then
            Cells(r, "F").Value = "no"
        End If
    Next r
Application.ScreenUpdating = True

End Sub
Thanks you so much. Worked perfectly first time. Makes that job so much easier.
 
Upvote 0

Forum statistics

Threads
1,225,626
Messages
6,186,090
Members
453,337
Latest member
fiaz ahmad

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