Date parameters

kenpcli

Board Regular
Joined
Oct 24, 2017
Messages
129
How do I use vba to look down a column of dates and if any dates = a Friday choose that date, if not choose most recent date.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
in my example, dates are in col A,
Day of Week is in col B, formula: =DoW(A2) 'see function below
col Q are the results of the search (alter as you need)
run MarkFri()
it looks in col B for FRI, then marks them found in col Q.
if none are found it marks the most recent date

Code:
Public Function DoW(ByVal pvDte)
DoW = Format(pvDte, "ddd")
End Function

Public Sub MarkFri()
Dim bFound As Boolean
Dim vNewest
Dim iRow As Long

Columns("Q:Q").ClearContents   'clear the found items

Range("A2").Select
While ActiveCell.Value <> ""
   If ActiveCell.Value > vNewest Then
      vNewest = ActiveCell.Value
      iRow = ActiveCell.Row
   End If
   
   If ActiveCell.Offset(0, 1).Value = "Fri" Then
       ActiveCell.Offset(0, 16).Value = "found"
       bFound = True
   End If
      
   ActiveCell.Offset(1, 0).Select  'next row
Wend

  'mark Q col.
If Not bFound Then Cells(iRow, 17).Value = "most recent"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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