VBA WorksheetFunction to match date

antaeusguy

Board Regular
Joined
Mar 8, 2010
Messages
81
I'm using Excel 2010.

I've created a Table where the first column consist of dates in dd.mm.yyyy format from 01.01.2011 to 31.12.2011.

I'm using VBA to match today's date with the table to obtain the row where today's date contains:

Code:
Sub HighlightTodayOverview()
    Dim Today As Date
    Dim TodayRow As Integer
    
    Today = Date
    TodayRow = Application.WorksheetFunction.Match(Today, Range("Table1[Date]"), 0)
    
    Debug.Print TodayRow
End Sub

However, I got this error message:

Run-time error '1004'
Unable to get the Match propertyof the WorksheetFunction class

Does anyone know what went wrong with the code?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I wouldn't use a worksheet function for this. Try either of these.
Code:
Sub HighlightTodayOverview()
    Dim Today As Date
    Dim TodayRow As Integer
    
    Today = Date
    TodayRow = Range("Table1[Date]").Find(What:=Today).Row

    Debug.Print TodayRow
End Sub

Sub HighlightTodayOverview2()
    Dim TodayRow As Integer
    
    With Range("Table1[Date]")
        TodayRow = .Row + DateDiff("d", .Cells(1).Value, Date)
    End With
    
    Debug.Print TodayRow
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,269
Messages
6,177,568
Members
452,784
Latest member
talippo

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