help please with matching cells in a LOOP

shabbyporpoise

New Member
Joined
Jul 22, 2011
Messages
26
Hello Forum
I am trying to loop through a doc. I want to test/match every item in the column against the first item, then loop and then test/match every item against the second item...and so on... and so on. I can successfully go through one column all the way to the end testing every item against the first item but when I get to the end of the list I get a run-time error 9 "subscript out of range" What am I missing?

Code:
Sub testArray()
   
   Dim rules(1 To 10000, 1 To 6) As String
   Dim intRow As Integer, intColumn As Integer, num As Integer
   Dim i As Integer, a As Integer, x As Integer
   
   num = InputBox("how many?")
   i = 1
   a = 1
   x = 1
   
   For intRow = 1 To num
   For intColumn = 1 To 6
        rules(intRow, intColumn) = Cells(intRow, intColumn).Value
     
    Next intColumn
    Next intRow
    
    For x = 2 To num
        For i = 2 To num
        
                If rules(i, 3) = rules(i - a, 3) Then '(error occurring here)
                    MsgBox "found a match"
                   
                 Else
                    MsgBox rules(i, 3) & " no match  " & rules(i - a, 3)
            
                End If
                a = a + 1
        Next i
        i = i + 1
    Next x
    
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,214
Messages
6,123,660
Members
449,114
Latest member
aides

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