Vba using Match with a date value

MrBD

New Member
Joined
Sep 12, 2022
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
I have a sheet with sequential dates in row 3, columns A to BJ. I've tried to match a date but I can only get it work via a helper cell.

Can anyone explain why in the vba

Range("B6").Value = DateValue("1/9/22")
Range("G9").Value = Application.WorksheetFunction.Match(Range("B6"), Range("A3:BJ3"), 0)

works perfectly, but

Range("G6").Value = Application.WorksheetFunction.Match(DateValue("1/9/22"), Range("A3:BJ3"), 0)

fails with a 1004 "Unable to match property..."
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try converting to a number value:

VBA Code:
Range("G6").Value = Application.WorksheetFunction.Match(CLng(DateValue("1/9/22")), Range("A3:BJ3"), 0)
 
Upvote 0
Solution
RoryA - you're a star - it worked perfectly! I tried everything I could think of but not the Clng. Many thanks.
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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