Macro - Find a date in a column range

bananashark

New Member
Joined
Jan 26, 2008
Messages
20
hi,

I have column S which lists some dates in the format "dd/mm/yyyy".

I would like a macro that searches to find todays date in this column.

If it doesn't find it, then I would like to append today's date at the end of the list.

If it finds it then I would like to put number "1" in column T in the row that the date is found.

thanking you in advance, bs :biggrin:
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Something like..

Sub DoDate()
Dim r As Range
Dim Flag As Boolean
Flag = True
lrow = Range("S65536").End(xlUp).Row
Set r = Range("S1:S" & lrow)
For Each c In r
If c.Value = Date Then
c.Offset(0, 1).Value = 1
Flag = False
Exit Sub
End If
Next
If Flag = True Then
Set r = r.Resize(r.Rows.Count + 1, 1)
r(r.Rows.Count).Value = Date
End If
End Sub
 
Upvote 0
Without looping

Code:
Sub FindToday()
Dim Found As Range, LR As Long
LR = Range("S" & Rows.Count).End(xlUp).Row
Set Found = Columns(19).Find(what:=Date)
If Found Is Nothing Then
    Range("S" & LR + 1).Value = Date
Else
    Found.Offset(0, 1).Value = 1
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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