Type Mismatch Error with Index Match with Dates at VBA

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi.
I want to find first date at Column C between today and next 15 days. I try many methods but always see Type Mismatch Error
I declare as Variant
I convert Date to number with CLng or CDbl, but See error again?
What is Problem?
VBA Code:
Sub IndexMatchDates()
Dim A As Long, P As Long
A = Application.Match(1, Application.Index((Range("C1:C21") > CLng(Date) - 1) * (Range("C1:C21") < CLng(Date) + 16), 0, 1), 0)

P = Application.Index(Range("C1:C21").Value2, Application.Match(1 _
, Application.Index((Range("C1:C21").Value2 > CDbl(Date) - 1) * (Range("C1:C21").Value2 < CDbl(Date) + 16), 0, 1), 0))
Debug.Print A
Debug.Print P
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
It's not the dates, it's the fact that VBA doesn't like doing array calculations like that.
Try
VBA Code:
A = Evaluate("match(1,Index((C1:C21 > today() - 1 )*(C1:C21<today() + 16), 0, 1),0)")
 
Upvote 0
Solution
Thanks. That was Trick. Same as Always. Very good and appropriate answer.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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