VBA Loop. Putting today's date into cell if certain conditions are met

Magoosball

Board Regular
Joined
Jun 4, 2017
Messages
70
Office Version
  1. 365
I am trying to write a script that will do the following:
  • Check to see if column N is empty. If column N isn't empty then go onto the next row. If it is empty then check to see if Column F contains the word "January". If Column F contains that word then put today's date into Column N.
  • Check to see if column O is empty. If column O isn't empty then go onto the next row. If it is empty then check to see if Column F contains the word "February" OR "March". If Column F contains either of those words then put today's date into Column O.
  • Check to see if column P is empty. If column P isn't empty then go onto the next row. If it is empty then check to see if Column F contains the word "April" OR "May" OR "June". If Column F contains any of those words then put today's date into Column P.

This should continue until the last row of the worksheet as dictated by no date in column A.
This is going to be ran daily to put today's date into Column N, O, P. This is why it is important to check to see if that column is empty before continuing.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
assuming column A is only dates and row 1 is headers
try this, adjust sheet name to suit
Code:
Sub testing()

    Dim i As Long

With Sheets("Sheet1")
    For i = 2 To .Cells(Rows.Count, "A").End(xlUp).Row
        If IsEmpty(.Cells(i, "N")) Then
            If InStr(.Cells(i, "F"), "January") > 0 Then .Cells(i, "N").Value = Date
        End If
        
        If IsEmpty(.Cells(i, "O")) Then
            If InStr(.Cells(i, "F"), "February") > 0 Or InStr(.Cells(i, "F"), "March") > 0 Then .Cells(i, "O").Value = Date
        End If
        
        If IsEmpty(.Cells(i, "P")) Then
            If InStr(.Cells(i, "F"), "April") > 0 Or InStr(.Cells(i, "F"), "May") > 0 Or InStr(.Cells(i, "F"), "June") > 0 Then .Cells(i, "P").Value = Date
        End If
    Next i
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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