I am new to using Arrays. I have written a macro to remove rows with a value that is captured from a column of data on a different worksheet in the same workbook. See code below:
The locCode(I) is what is giving me the Subscript out of Range error. Any help would be greatly appreciated.
HTML:
Sub Test()
Dim LastRow As Long, I As Long
Dim locRng As Range, FoundCell As Range
Dim locCode As Variant
Dim shSheet1 As Worksheet, shSheet2 As Worksheet
Set shSheet1 = Worksheets("Resource")
Set shSheet2 = Worksheets("Raw Data")
LastRow = Cells(65536, 1).End(xlUp).Row
Set locRng = shSheet2.Range("E2:E" & LastRow)
locCode = shSheet1.Range("M2:M14").Value
With shSheet2
.Select
With locRng
For I = LBound(locCode) To UBound(locCode)
Do
Set FoundCell = locRng.Find(What:=locCode(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
Next I
End With
End With
End Sub
The locCode(I) is what is giving me the Subscript out of Range error. Any help would be greatly appreciated.