Я пытаюсь создать массив, цикл от UBound
до LBound
и проверить значения с помощью приведенного ниже кода.
Я получаю сообщение об ошибке:
If arrPart(i) = strResult Then
Ошибка времени выполнения 9
Диапазон, который я пытаюсь импортировать в массив:

Код:
Option Explicit
Sub ArrayTest()
Dim LastColumn As Long, CounterPart As Long, i As Long
Dim arrPart As Variant
Dim strResult As String
With ThisWorkbook.Worksheets("Sheet1")
LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
strResult = "N"
'Set as an array the 4 last matches
arrPart = .Range(Cells(1, LastColumn - 3), Cells(1, LastColumn))
CounterPart = 0
For i = UBound(arrPart) To LBound(arrPart) Step -1
If arrPart(i) = strResult Then
CounterPart = CounterPart + 1
Else
Exit For
End If
Next
End With
End Sub
есть предложения?