Find function referencing a cell value

nbh45

New Member
Joined
Aug 3, 2011
Messages
3
I'm trying to create a macro that will take the user to the current day in a large excel calendar when they click a button. I'm currently attempting to do this using the find function by having it look up the current date in a cell in the worksheet, which date is updated using the TODAY() formula. The current date (i.e., the TODAY() formula) is in cell F4, and the calendar is in cells C13:J1000.

Anyway, I'm very new to VBA, but below is my attempt. If I enter in a day that I want, for example "Wednesday, August 03, 2011" I can get it to work, but I would like it to automatically update so other users can simply click the button to go to the current day. However, I have been unable to get that to work so far - the "Not Found" message box is all that gets returned.

Any suggestions or ideas would be greatly appreciated. Thanks!

Sub Findinrange1()

Range("C13:J1000").Select

mystring = ActiveSheet.Cells(4, 6).Value
Set RangeObj = Selection.Find(What:=mystring, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If RangeObj Is Nothing Then MsgBox "Not Found" Else RangeObj.Select
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,

Try this

Code:
Sub Findinrange1()
    Dim myDate As Date
    Dim RangeObj As Range
 
    myDate = ActiveSheet.Cells(4, 6).Value
    Set RangeObj = Range("C13:J1000").Find(What:=myDate, After:=ActiveCell, _
    LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False)
    If RangeObj Is Nothing Then MsgBox "Not Found" Else RangeObj.Select
End Sub

HTH

M.
 
Upvote 0
Hi Marcelo,

Thanks for the idea. Unfortunately, that returns a run-time error 12 - type mismatch. Thanks though!
 
Upvote 0
Hi Marcelo,

Thanks for the idea. Unfortunately, that returns a run-time error 12 - type mismatch. Thanks though!

Do you have real-dates in your calendar or strings (text)?

If you have the dates as text change the
Dim myDate as Date

to
Dim myDate as String

M.
 
Upvote 0
They are real dates. The user inputs the first Monday of the calendar and then the remaining dates are calculated off that date. No luck trying to evaluate as a String - still get the 'type mismatch' error.

-N
 
Upvote 0
They are real dates. The user inputs the first Monday of the calendar and then the remaining dates are calculated off that date. No luck trying to evaluate as a String - still get the 'type mismatch' error.

-N

hmmm...

It worked for me with real dates and
Dim myDate as Date

I dont know why it is not working for you...

M.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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