#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default TODAY MACRO

I have been running this macro for the last 4 weeks with success until the
date changed to 01-Apr-08 when it started giving the error message below I
have checked the format of the date cells and they are ok. Any ideas why it
is not working

Macro is
Sub GOTOTOALL()
Range("D17:HO17").Find(Format(Now(), "dd-mmm-yy"), , xlValues).Select
End Sub

Error
Run Time error: "91"
Object variable or With block variable not set


Best regards

Stuart

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default TODAY MACRO

Untested:

Option Explicit
Sub GOTOTOALL()
Dim FoundCell As Range
With ActiveSheet.Range("D17:HO17")
Set FoundCell = .Cells.Find(what:=CLng(Date), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
Beep 'not found
Else
FoundCell.Select
End If
End Sub

But dates in VBA can be painful to work with (as you've seen!).

Since you're only looking in a single row, you may want to try this if the first
suggestion doesn't work:

Option Explicit
Sub GOTOTOALL2()
Dim res As Variant
Dim myRng As Range

Set myRng = ActiveSheet.Range("D17:HO17")

res = Application.Match(CLng(Date), myRng, 0)

If IsError(res) Then
Beep
Else
myRng(res).Select
End If
End Sub

Stuart WJG wrote:

I have been running this macro for the last 4 weeks with success until the
date changed to 01-Apr-08 when it started giving the error message below I
have checked the format of the date cells and they are ok. Any ideas why it
is not working

Macro is
Sub GOTOTOALL()
Range("D17:HO17").Find(Format(Now(), "dd-mmm-yy"), , xlValues).Select
End Sub

Error
Run Time error: "91"
Object variable or With block variable not set

Best regards

Stuart


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default TODAY MACRO

Dave
Used 2nd option. Fantastic done the job
agreat help

Thanks

"Dave Peterson" wrote:

Untested:

Option Explicit
Sub GOTOTOALL()
Dim FoundCell As Range
With ActiveSheet.Range("D17:HO17")
Set FoundCell = .Cells.Find(what:=CLng(Date), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
Beep 'not found
Else
FoundCell.Select
End If
End Sub

But dates in VBA can be painful to work with (as you've seen!).

Since you're only looking in a single row, you may want to try this if the first
suggestion doesn't work:

Option Explicit
Sub GOTOTOALL2()
Dim res As Variant
Dim myRng As Range

Set myRng = ActiveSheet.Range("D17:HO17")

res = Application.Match(CLng(Date), myRng, 0)

If IsError(res) Then
Beep
Else
myRng(res).Select
End If
End Sub

Stuart WJG wrote:

I have been running this macro for the last 4 weeks with success until the
date changed to 01-Apr-08 when it started giving the error message below I
have checked the format of the date cells and they are ok. Any ideas why it
is not working

Macro is
Sub GOTOTOALL()
Range("D17:HO17").Find(Format(Now(), "dd-mmm-yy"), , xlValues).Select
End Sub

Error
Run Time error: "91"
Object variable or With block variable not set

Best regards

Stuart


--

Dave Peterson

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
set up macro to goto cell with "today" in Stuart WJG Excel Worksheet Functions 7 March 13th 08 03:19 PM
prob with TODAY() within a macro deepika :excel help[_2_] Excel Discussion (Misc queries) 2 February 28th 08 09:52 PM
Open an Excel file with a date as today in a macro Perry Excel Discussion (Misc queries) 4 November 10th 05 09:57 AM
How to record macro to print pages modified today pamiam3333 Excel Worksheet Functions 1 September 10th 05 02:36 AM
=IF(OR(TODAY()G9),"Pass","Overdue") Why doe it not wo. Fkor Excel Discussion (Misc queries) 3 March 10th 05 08:29 AM


All times are GMT +1. The time now is 07:10 PM.

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"