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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

konew1

Well-known Member
Joined
Oct 17, 2007
Messages
2,287
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
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
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?
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Perhaps set your Array variables as below !!!!
Code:
datekeyArray = Sheets(2).Range("a2:c14").Value
    dataArray = Sheets(1).Range("a2:r6771").Value
 

NatetheGreat

Active Member
Joined
Nov 18, 2013
Messages
268
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,683
Messages
5,637,780
Members
416,982
Latest member
lisam77

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
Top