Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to compare today's date to a cell on VBA?


Hi,

I'm trying to create a macro which will:
-Open on the sheet1
-Get today's date
-Compare today's date to a certain cell in the sheet
-If today's date is bigger (=the date on the cell has passed) - it'll
move to the next sheet and so on to the next sheets.

I thought you might have some suggestions, anyone?

Thanks,

Sivan.


--
Sivangen
------------------------------------------------------------------------
Sivangen's Profile: http://www.excelforum.com/member.php...o&userid=34925
View this thread: http://www.excelforum.com/showthread...hreadid=546614

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to compare today's date to a cell on VBA?

Maybe something like:

Option Explicit
Sub auto_open()

Dim myDate As Date
Dim myAddr As String
Dim wCtr As Long

myDate = Date
myAddr = "a1"

For wCtr = 1 To ThisWorkbook.Worksheets.Count
If Worksheets(wCtr).Range("a1").Value <= myDate Then
Application.Goto Worksheets(wCtr).Range("a1"), Scroll:=True
Exit For
End If
Next wCtr

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Sivangen wrote:

Hi,

I'm trying to create a macro which will:
-Open on the sheet1
-Get today's date
-Compare today's date to a certain cell in the sheet
-If today's date is bigger (=the date on the cell has passed) - it'll
move to the next sheet and so on to the next sheets.

I thought you might have some suggestions, anyone?

Thanks,

Sivan.

--
Sivangen
------------------------------------------------------------------------
Sivangen's Profile: http://www.excelforum.com/member.php...o&userid=34925
View this thread: http://www.excelforum.com/showthread...hreadid=546614


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to compare today's date to a cell on VBA?

Hello Dave,

Shouldn't it be

If Worksheets(wCtr).Range("a1").Value = myDate Then

I thought he said move on when the date in the sheet had passed.

-If today's date is bigger (=the date on the cell has passed) - it'll

move to the next sheet and so on to the next sheets.


--
Regards,
Tom Ogilvy



"Dave Peterson" wrote:

Maybe something like:

Option Explicit
Sub auto_open()

Dim myDate As Date
Dim myAddr As String
Dim wCtr As Long

myDate = Date
myAddr = "a1"

For wCtr = 1 To ThisWorkbook.Worksheets.Count
If Worksheets(wCtr).Range("a1").Value <= myDate Then
Application.Goto Worksheets(wCtr).Range("a1"), Scroll:=True
Exit For
End If
Next wCtr

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Sivangen wrote:

Hi,

I'm trying to create a macro which will:
-Open on the sheet1
-Get today's date
-Compare today's date to a certain cell in the sheet
-If today's date is bigger (=the date on the cell has passed) - it'll
move to the next sheet and so on to the next sheets.

I thought you might have some suggestions, anyone?

Thanks,

Sivan.

--
Sivangen
------------------------------------------------------------------------
Sivangen's Profile: http://www.excelforum.com/member.php...o&userid=34925
View this thread: http://www.excelforum.com/showthread...hreadid=546614


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to compare today's date to a cell on VBA?

That seems like a very reasonable suggestion <bg.

Thanks for the correction.

Tom Ogilvy wrote:

Hello Dave,

Shouldn't it be

If Worksheets(wCtr).Range("a1").Value = myDate Then

I thought he said move on when the date in the sheet had passed.

-If today's date is bigger (=the date on the cell has passed) - it'll

move to the next sheet and so on to the next sheets.

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote:

Maybe something like:

Option Explicit
Sub auto_open()

Dim myDate As Date
Dim myAddr As String
Dim wCtr As Long

myDate = Date
myAddr = "a1"

For wCtr = 1 To ThisWorkbook.Worksheets.Count
If Worksheets(wCtr).Range("a1").Value <= myDate Then
Application.Goto Worksheets(wCtr).Range("a1"), Scroll:=True
Exit For
End If
Next wCtr

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Sivangen wrote:

Hi,

I'm trying to create a macro which will:
-Open on the sheet1
-Get today's date
-Compare today's date to a certain cell in the sheet
-If today's date is bigger (=the date on the cell has passed) - it'll
move to the next sheet and so on to the next sheets.

I thought you might have some suggestions, anyone?

Thanks,

Sivan.

--
Sivangen
------------------------------------------------------------------------
Sivangen's Profile: http://www.excelforum.com/member.php...o&userid=34925
View this thread: http://www.excelforum.com/showthread...hreadid=546614


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to compare today's date to a cell on VBA?


Thanks guys, you've helped me a lot!


--
Sivangen
------------------------------------------------------------------------
Sivangen's Profile: http://www.excelforum.com/member.php...o&userid=34925
View this thread: http://www.excelforum.com/showthread...hreadid=546614

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
conditional formatting for cell date to equal today's date Sistereinstein Excel Worksheet Functions 2 September 10th 12 07:53 PM
date in Cell to change colors if the date is beyond today's date Pete Elbert Excel Discussion (Misc queries) 2 June 6th 09 06:31 AM
How to use Today's date in a cell and make it stay the same date ADSK Excel Discussion (Misc queries) 6 November 17th 08 07:34 PM
text and today's date in 1 cell rexie3 Excel Discussion (Misc queries) 5 February 8th 07 10:38 PM
find cell with today's date James D Excel Discussion (Misc queries) 2 January 16th 06 09:59 PM


All times are GMT +1. The time now is 11:49 AM.

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

About Us

"It's about Microsoft Excel"