Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default VBA find today's date in Column A

Hi,

I have the date for everyday in column A from 2001 out to 2015. I want a
vba function that finds today's date in column A and makes it the active cell.

Can anyone help please?

Thanks,

B/
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VBA find today's date in Column A

Sub find_date()
Dim d As Date, i As Long
d = Date
For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(i, "A").Value = d Then
Cells(i, "A").Select
Exit Sub
End If
Next
End Sub

--
Gary''s Student - gsnu200738


"Bhupinder Rayat" wrote:

Hi,

I have the date for everyday in column A from 2001 out to 2015. I want a
vba function that finds today's date in column A and makes it the active cell.

Can anyone help please?

Thanks,

B/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default VBA find today's date in Column A

The following should allow you to enter a date at the input box and the find
method will find and activate the cell with the date. If not found then a
message is displayed.

Note the comment about editing to insert your worksheet name
Sub Find_Date()

Dim rng1 As Range
Dim dateStr As String
Dim dateToFind As Date
Dim foundDate As Range

'Get date as string value
dateStr = InputBox("Enter the date to be found")

'Convert string value to date format
dateToFind = DateValue(dateStr)

'Edit Sheet1 to your worksheet name
Set rng1 = Sheets("Sheet1").Range(Cells(1, 1), _
Cells(Rows.Count, 1).End(xlUp))

Set foundDate = rng1.Find(What:=dateToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundDate Is Nothing Then
foundDate.Select
Else
MsgBox dateStr & " not found"
End If


End Sub

Regards,

OssieMac

"Bhupinder Rayat" wrote:

Hi,

I have the date for everyday in column A from 2001 out to 2015. I want a
vba function that finds today's date in column A and makes it the active cell.

Can anyone help please?

Thanks,

B/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default VBA find today's date in Column A

My apologies. You wanted to find today's date not a date you input and I
copied a macro that I had without amending it so try this code instead.

Sub Find_Date_2()

Dim rng1 As Range
Dim dateToFind As Date
Dim foundDate As Range

dateToFind = Date 'This is today's date

'Edit Sheet1 to your sheet name
Set rng1 = Sheets("Sheet1").Range(Cells(1, 1), _
Cells(Rows.Count, 1).End(xlUp))

Set foundDate = rng1.Find(What:=dateToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundDate Is Nothing Then
foundDate.Select
Else
MsgBox dateStr & " not found"
End If


End Sub

Regards,

OssieMac

"OssieMac" wrote:

The following should allow you to enter a date at the input box and the find
method will find and activate the cell with the date. If not found then a
message is displayed.

Note the comment about editing to insert your worksheet name
Sub Find_Date()

Dim rng1 As Range
Dim dateStr As String
Dim dateToFind As Date
Dim foundDate As Range

'Get date as string value
dateStr = InputBox("Enter the date to be found")

'Convert string value to date format
dateToFind = DateValue(dateStr)

'Edit Sheet1 to your worksheet name
Set rng1 = Sheets("Sheet1").Range(Cells(1, 1), _
Cells(Rows.Count, 1).End(xlUp))

Set foundDate = rng1.Find(What:=dateToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundDate Is Nothing Then
foundDate.Select
Else
MsgBox dateStr & " not found"
End If


End Sub

Regards,

OssieMac

"Bhupinder Rayat" wrote:

Hi,

I have the date for everyday in column A from 2001 out to 2015. I want a
vba function that finds today's date in column A and makes it the active cell.

Can anyone help please?

Thanks,

B/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default VBA find today's date in Column A

Both pieces of code are good.

Thanks Guys,

B/

"OssieMac" wrote:

My apologies. You wanted to find today's date not a date you input and I
copied a macro that I had without amending it so try this code instead.

Sub Find_Date_2()

Dim rng1 As Range
Dim dateToFind As Date
Dim foundDate As Range

dateToFind = Date 'This is today's date

'Edit Sheet1 to your sheet name
Set rng1 = Sheets("Sheet1").Range(Cells(1, 1), _
Cells(Rows.Count, 1).End(xlUp))

Set foundDate = rng1.Find(What:=dateToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundDate Is Nothing Then
foundDate.Select
Else
MsgBox dateStr & " not found"
End If


End Sub

Regards,

OssieMac

"OssieMac" wrote:

The following should allow you to enter a date at the input box and the find
method will find and activate the cell with the date. If not found then a
message is displayed.

Note the comment about editing to insert your worksheet name
Sub Find_Date()

Dim rng1 As Range
Dim dateStr As String
Dim dateToFind As Date
Dim foundDate As Range

'Get date as string value
dateStr = InputBox("Enter the date to be found")

'Convert string value to date format
dateToFind = DateValue(dateStr)

'Edit Sheet1 to your worksheet name
Set rng1 = Sheets("Sheet1").Range(Cells(1, 1), _
Cells(Rows.Count, 1).End(xlUp))

Set foundDate = rng1.Find(What:=dateToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundDate Is Nothing Then
foundDate.Select
Else
MsgBox dateStr & " not found"
End If


End Sub

Regards,

OssieMac

"Bhupinder Rayat" wrote:

Hi,

I have the date for everyday in column A from 2001 out to 2015. I want a
vba function that finds today's date in column A and makes it the active cell.

Can anyone help please?

Thanks,

B/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
create button to find today's date in another tab kjedgar65 Excel Worksheet Functions 1 March 22nd 09 09:14 AM
Can't find today's date Otto Moehrbach Excel Programming 6 March 12th 06 09:39 PM
Find Today's Date in a List-- How? GaryCam Excel Programming 5 March 11th 06 12:56 PM
find cell with today's date James D Excel Discussion (Misc queries) 2 January 16th 06 09:59 PM
Find and display today's date cel awander Excel Programming 3 May 24th 04 05:49 PM


All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"