Problems with dates in Array

NatetheGreat

Active Member
Joined
Nov 18, 2013
Messages
268
Hi I have the following code.

Code:
Option ExplicitSub pull()
Dim date1 As String
Dim datekeyArray() As Variant
Dim dataArray() As Variant
Sheets(2).Select
datekeyArray = Range("a2:c14")
Sheets(1).Select
dataArray = Range("a2:r6771")






If dataArray(1, 1) > datekeyArray(1, 1) Then
MsgBox ("yes")
Else: MsgBox ("no")
End If










End Sub

For some reason the VBE here is firing NO, even though the value of dataarray(1,1) is equal to 01/04/2014 and the value of datekeyarray(1,1) is equal to 02/09/2013. Obviously 02/09/2013 is before 01/04/2013, so I am not sure why this is flagging no?

Thanks
Natethegreat
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
For some reason the VBE here is firing NO, even though the value of dataarray(1,1) is equal to 01/04/2014 and the value of datekeyarray(1,1) is equal to 02/09/2013. Obviously 02/09/2013 is before 01/04/2013, so I am not sure why this is flagging no?

Is 02/09/2013 09Feb and 01/04/2013 04 Jan? then 02/09/2013 is not before 01/04/2013
If
02/09/2013 is 02 Sept, and 01/04/2013 is 01 April then 02/09/2013 is still not before 01/04/2013
 
Upvote 0
Your wording is off...

For some reason the VBE here is firing NO, even though the value of dataarray(1,1) is equal to 01/04/2014 and the value of datekeyarray(1,1) is equal to 02/09/2013. Obviously 02/09/2013 is before 01/04/2013, so I am not sure why this is flagging no?
 
Upvote 0
Perhaps set your Array variables as below !!!!
Code:
datekeyArray = Sheets(2).Range("a2:c14").Value
    dataArray = Sheets(1).Range("a2:r6771").Value
 
Upvote 0
Hi all,

The reason this was happening was because the cells of one of the arrays was set to text, and one was set to date. So when the arrays were being populated they weren't being compared properly hence why the logic was failing.

Thanks
nate
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,668
Members
448,977
Latest member
moonlight6

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