The script below works without
.Offset(1, -4).Resize(.Rows.Count - 1, 1).Value = "TEST"
The script takes a list of iPads and Tablets on a spreadsheet and finds the ones that don't have SIM cards.
With the intended results, I need to offset back 2-3 columns and change D & E's result to "TEST" for example.
The code below runs for the G column and to get offset to work means expanding from (A:T). This breaks everything below though and now the script loses focus and doesn't know what to filter.
I know either set range needs changing, or I need to approach offset differently without losing the focus and accidently changing rows that aren't filtered.
Sub FilterOut()
Dim arr(): Dim arrResult()
Dim rg As Range: Dim i As Long
Set rg = Range("G:G")
arr = Application.Transpose(rg)
For i = LBound(arr) To UBound(arr)
If InStr(arr(i), "SAMSUNG TABLET") <> 0 Or InStr(arr(i), "IPAD") <> 0 Then
If InStr(arr(i), "64GB") <> 0 Then arr(i) = Replace(arr(i), "64GB", "!@!")
If InStr(arr(i), "CELL") = 0 And InStr(arr(i), "4G") = 0 And InStr(arr(i), "5G") = 0 Then
If InStr(arr(i), "!@!") <> 0 Then arr(i) = Replace(arr(i), "!@!", "64GB")
j = j + 1
ReDim Preserve arrResult(1 To j)
arrResult(j) = arr(i)
End If
End If
Next i
With rg
.AutoFilter Field:=1, criteria1:=arrResult, Operator:=xlFilterValues
'My issue starts here:
.Offset(1, -4).Resize(.Rows.Count - 1, 1).Value = "TEST"
End With
End Sub
I tried:
Set rg = Range("A:T")
.Offset(1, -4).Resize(.Rows.Count - 1, 1).Value = "TEST"
Run time error - Subscript error out of range