VBA Array Subscript Out of Range

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Hello, below is the code I am using and I keep getting "Subscript out of range" error at the highlighted line.
I have no idea why I am getting it.

Any advices or tips would help alot,
Thank you very much!

PS: LR is always bigger than 2 and the code has been pasted into Worksheet module.

Rich (BB code):
Option Base 0
Sub a()
    Dim LR As Long, i As Long, skipArr() As Long, j As Long, count As Long
    Dim check As Boolean
    count = 0
    LR = Range("A" & Rows.count).End(xlUp).Row
    ReDim skipArray(0 To LR - 2) As Long
    For i = 2 To LR
        check = True
        For j = 1 To count
            If skipArray(j) = i Then
                check = False
            End If
        Next j
        
        If check Then
            For j = i + 1 To LR
                If Range("B" & i).Value = Range("C" & j).Value And Range("C" & i).Value = Range("B" & j).Value Then
                    Range("A" & j).ClearContents
                    skipArr(count) = j
                    count = count + 1
                End If
            Next j
        End If
    Next i
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Pick a name -- SkipArr or SkipArray -- you've got both, but only one is initialized.
 
Upvote 0
Hi,
I think, that You have to declare the array skipArr using ReDim, You declared the array skipArray, best regards.
 
Upvote 0
The array you redimmed is called skipArray, you are referring to skipArr which hasn't been dimensioned.

Unfortunately Option Explicit wouldn't pick this up as the Redim is considered a declaration.

Well that's why I think it won't.:)
 
Upvote 0

Forum statistics

Threads
1,203,094
Messages
6,053,503
Members
444,667
Latest member
KWR21

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