Hello Masters of Excel,
I am trying to write a procedure that will read a column of dates via a range, assign that range to an array of variants and then compare that array to another to see if it has expired.
I have success with reading the range to an array of variants but cannot get past this point. Every time I attempt to view, compare etc. the array of variants I get error code : 9 - which I am under the impression that I am "out of bounds." To corroborate my theory I have attempted to redimension my array to a specific bound (1 TO 10) but then lose all the data that was previously assigned from my range.
Here is the code:
*****************************************************
Sub LoopTest()
'{1} Define Variable Arrays for [1]Drilling Dates, [2]Expiration Dates & TRS, [2] NMA & TRS
Dim Drill_Date_Array() As Variant
Dim Expiration_Date() As Variant
Dim Expiration_TRS() As Variant
Dim NMA() As Variant
Dim NMA_TRS() As Variant
Dim Drill_Record() As Variant
'{2} Define Variables for temporary holding places for a range
Dim Temp_Array_A() As Variant
Dim Max_A As Integer
Dim Test_String As String
Dim Temp_Array_C() As Variant
Dim Temp_Array_D() As Variant
Dim Temp_Array_F() As Variant
Dim Temp_Array_G() As Variant
Dim Temp_Array_I() As Variant
'{3} Populate Variable Arrays at {1}
Drill_Date_Array = Range("A2:A8").Value
Expiration_Date = Range("C2:C8").Value
Expiration_TRS = Range("D2:D8").Value
NMA = Range("F2:F8").Value
NMA_TRS = Range("G2:G8")
Drill_Record = Range("I2:I8")
'{4} Print Variable Arrays (Initially)
Temp_Array_A = Drill_Date_Array
Range("A20:A30").Value = Temp_Array_A
'Max_A = ThisWorkbook.Names.Count
ReDim Temp_Array_A(1 To 10)
Temp_Array_C = Expiration_Date
Range("C20:C30") = Temp_Array_C
Temp_Array_D = Expiration_TRS
Range("D20:D30") = Temp_Array_D
Temp_Array_F = NMA
Range("F20:F30") = Temp_Array_F
Temp_Array_G = NMA_TRS
Range("G20:G30") = Temp_Array_G
Temp_Array_I = Drill_Record
Range("I20:I30") = Temp_Array_I
'{5} Test if Lease Expiration is within 21 days of 1st drill date to determine if expiration should be drilled
Dim i As Integer
Dim Message_Text As String
For i = LBound(Temp_Array_A) To UBound(Temp_Array_A)
Next i
'If DateValue(Temp_Array_A(1)) < DateValue(Temp_Array_C(1)) Then MsgBox ("Drill Date Less") Else: MsgBox ("Expiration Date Less")
End Sub
***********************************************
Any and all help is VERY MUCH APPRECIATED
Thank you!
I am trying to write a procedure that will read a column of dates via a range, assign that range to an array of variants and then compare that array to another to see if it has expired.
I have success with reading the range to an array of variants but cannot get past this point. Every time I attempt to view, compare etc. the array of variants I get error code : 9 - which I am under the impression that I am "out of bounds." To corroborate my theory I have attempted to redimension my array to a specific bound (1 TO 10) but then lose all the data that was previously assigned from my range.
Here is the code:
*****************************************************
Sub LoopTest()
'{1} Define Variable Arrays for [1]Drilling Dates, [2]Expiration Dates & TRS, [2] NMA & TRS
Dim Drill_Date_Array() As Variant
Dim Expiration_Date() As Variant
Dim Expiration_TRS() As Variant
Dim NMA() As Variant
Dim NMA_TRS() As Variant
Dim Drill_Record() As Variant
'{2} Define Variables for temporary holding places for a range
Dim Temp_Array_A() As Variant
Dim Max_A As Integer
Dim Test_String As String
Dim Temp_Array_C() As Variant
Dim Temp_Array_D() As Variant
Dim Temp_Array_F() As Variant
Dim Temp_Array_G() As Variant
Dim Temp_Array_I() As Variant
'{3} Populate Variable Arrays at {1}
Drill_Date_Array = Range("A2:A8").Value
Expiration_Date = Range("C2:C8").Value
Expiration_TRS = Range("D2:D8").Value
NMA = Range("F2:F8").Value
NMA_TRS = Range("G2:G8")
Drill_Record = Range("I2:I8")
'{4} Print Variable Arrays (Initially)
Temp_Array_A = Drill_Date_Array
Range("A20:A30").Value = Temp_Array_A
'Max_A = ThisWorkbook.Names.Count
ReDim Temp_Array_A(1 To 10)
Temp_Array_C = Expiration_Date
Range("C20:C30") = Temp_Array_C
Temp_Array_D = Expiration_TRS
Range("D20:D30") = Temp_Array_D
Temp_Array_F = NMA
Range("F20:F30") = Temp_Array_F
Temp_Array_G = NMA_TRS
Range("G20:G30") = Temp_Array_G
Temp_Array_I = Drill_Record
Range("I20:I30") = Temp_Array_I
'{5} Test if Lease Expiration is within 21 days of 1st drill date to determine if expiration should be drilled
Dim i As Integer
Dim Message_Text As String
For i = LBound(Temp_Array_A) To UBound(Temp_Array_A)
Next i
'If DateValue(Temp_Array_A(1)) < DateValue(Temp_Array_C(1)) Then MsgBox ("Drill Date Less") Else: MsgBox ("Expiration Date Less")
End Sub
***********************************************
Any and all help is VERY MUCH APPRECIATED
Thank you!