0

I want the code below to do evaluate each line in a dataset, match column 35 to a range and then paste in the correct tab.

I'm having trouble with the If Not IsError statement. In an instance where the match doesn't occur, I want the If Not Then to skip the remaining nested code and jump to the end of the For Loop, moving to the next row iRow.

Sub testFind()    
    Dim csCount As Range
    Dim b As Variant
    Dim shrow As Long
    Dim iRow As Long, iRowL As Long, var As Variant
    Dim bln As Boolean
    Dim s As String
    Dim eRow As Integer

    Set csCount = Worksheets("Input").Range("csCount")   
    iRowL = Cells(rows.count, 1).End(xlUp).Row

    For iRow = 2 To iRowL  
        If Not IsEmpty(Cells(iRow, 35)) Then
            bln = False
            var = Application.Match(Cells(iRow, 35).Value, Worksheets("Input").Columns(3), 0)
            If Not IsError(var) Then
                Sheets("GL008").rows(iRow).copy
                s = Sheets("GL008").Cells(iRow, 35)
                Sheets(s).Activate
                eRow = Sheets(s).Cells(rows.count, 1).End(xlUp).Offset(1, 0).Row
                ActiveSheet.Paste Destination:=Sheets(s).rows(eRow)
            End If
        End If   
    Next iRow   
End Sub
Community
  • 1
  • 1
KM617
  • 137
  • 1
  • 3
  • 16

1 Answers1

1

Use CvErr

Instead of

If Not IsError(Var) Then
    '
    '~~> Rest of the code
    '
End If

use this

If Not CVErr(Var) = CVErr(xlErrNA) Then
    '
    '~~> Rest of the code
    '
End If
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250