Hi all,
Can anyone tell me what is worng with the following piece of code? Even though the code under both conditions works well spearately, however I construct the If statement, Excel never gets to execute the Else part. Please help!
For i = 2 To nrLines
Dim Val As Long
Val = Sheets("I Pairs").Cells(i, 1).Value
Sheets("Lin Car").Select
ActiveSheet.Range(Range("A1"), Cells.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=19, Criteria1:=Val
If Not Val Then
MsgBox "No records found" & " " & Val
ElseIf Val Then
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "S").End(xlUp).Row
End With
Cells(LastRow, 19).EntireRow.Select
Selection.Rows.Interior.ColorIndex = 38
End If
Next i
Thanks a lot,
Alex
Can anyone tell me what is worng with the following piece of code? Even though the code under both conditions works well spearately, however I construct the If statement, Excel never gets to execute the Else part. Please help!
For i = 2 To nrLines
Dim Val As Long
Val = Sheets("I Pairs").Cells(i, 1).Value
Sheets("Lin Car").Select
ActiveSheet.Range(Range("A1"), Cells.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=19, Criteria1:=Val
If Not Val Then
MsgBox "No records found" & " " & Val
ElseIf Val Then
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "S").End(xlUp).Row
End With
Cells(LastRow, 19).EntireRow.Select
Selection.Rows.Interior.ColorIndex = 38
End If
Next i
Thanks a lot,
Alex