Comparing two arrays using a set of shared values

em4t1113

New Member
Joined
Jun 27, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I'm hoping you can help with an error? I'm getting error 9, subscript out of range for the very first if statement. The end goal is to be able to use the two "id" arrays to compare the matching values in the "finish" arrays to each other. The IDs are all unique and are consistent between the two arrays. I'd appreciate any advice you can give! Thank you. Here is the entirety of the applicable code:

Dim id1() As Variant
'Dim id1I As Interior
Dim id2() As Variant
'Dim id2I As Interior
Dim finish1() As Variant
'Dim finish1I As Interior
Dim finish2() As Variant
'Dim finish2I As Interior
Dim c As Variant, a As Variant

Set past = ThisWorkbook.Worksheets("Practice S 2")
Set present = ThisWorkbook.Worksheets("Practice S")
lastRow = past.Cells(Rows.Count, "D").End(xlUp).Row

id1 = past.Range("D2:D" & lastRow)
id2 = present.Range("D2:D" & lastRow)
finish1 = past.Range("I2:I" & lastRow)
finish2 = present.Range("I2:I" & lastRow)

For c = 1 To UBound(id1, 1)
Debug.Print id1(c, 1)
Next c
For c = 1 To UBound(finish1, 1)
Debug.Print finish1(c, 1)
Next c

For c = LBound(id1, 1) To UBound(id1, 1)
For a = LBound(id2, 1) To UBound(id2, 1)
If id1(c) = id2(a) Then ' And id1(c) <> "" Then
forecastFin = finish1(c)

MsgBox ("Matched ID: " & forecastFin)

'If (forecastFin) <= CDate(MeDate) And (forecastFin) >= CDate(MpDate) Then
' forecastFinCount = forecastFinCount + 1

'End If
End If
Next a
Next c
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,584
Messages
6,179,693
Members
452,938
Latest member
babeneker

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