Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup formula with date test

I have a situation in which I need to find a date in an array of dates.
For example, for the date value
9/9/03

in the array:

Month



------------------------------------------------
Message posted from http://www.ExcelForum.com/

-- View and post Excel related usenet messages directly from http://www.ExcelForum.com
-- Hundreds of free MS Excel tips, tricks and solutions at http://www.ExcelTip.com/
------------------------------------------------
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Lookup formula with date test

I think that something like should work. But it didn't work for me. I've
always had trouble in VBA with dates.

Option Explicit
Sub testm01()

Dim res As Variant
Dim myMonth As Variant
Dim mydate As Date

myMonth = Array(DateSerial(2003, 1, 1), DateSerial(2003, 9, 9))

res = Application.Match(DateSerial(2003, 9, 9), myMonth, 0)

If IsError(res) Then
MsgBox "error"
Else
MsgBox "ok"
End If

End Sub

But if you can convert your dates to longs, the same kind of thing works ok:

Option Explicit
Sub testme03()

Dim myArr(1 To 12) As Long
Dim mydate As Long
Dim iCtr As Long
Dim res As Variant

'just test data
For iCtr = lbound(myArr) to ubound(myArr)
myArr(iCtr) = CLng(DateSerial(2003, iCtr, 3))
Next iCtr
mydate = CLng(DateSerial(2003, 8, 3))

'real stuff here

res = Application.Match(mydate, myArr, 0)
If IsError(res) Then
MsgBox Format(mydate, "mm/dd/yyyy") & " wasn't found"
Else
MsgBox Format(mydate, "mm/dd/yyyy") & " was found as element: " & res
End If

End Sub



jethawk wrote:

I have a situation in which I need to find a date in an array of dates.
For example, for the date value
9/9/03

in the array:

Month

------------------------------------------------
Message posted from http://www.ExcelForum.com/

-- View and post Excel related usenet messages directly from http://www.ExcelForum.com
-- Hundreds of free MS Excel tips, tricks and solutions at http://www.ExcelTip.com/
------------------------------------------------


--

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
Logical Test on Date value Sheila D Excel Discussion (Misc queries) 1 September 25th 08 07:01 PM
Convert test to date GKW in GA Excel Discussion (Misc queries) 21 December 13th 07 05:22 PM
test to Julian date curtev Excel Discussion (Misc queries) 10 July 9th 07 11:46 PM
Test plus date and time Kelly Excel Worksheet Functions 1 December 12th 05 07:51 PM
test for date in column question Buster Excel Worksheet Functions 1 December 10th 04 04:38 AM


All times are GMT +1. The time now is 03:26 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"