I am trying to loop through visible rows (after having applied a filter) in an Excel worksheet and display all of the cells in a certain column in these visible rows. I have a for loop that works, however, I wish to avoid the first row which contains a header and which is printed in my loop.
To do this, I inserted an if condition that would exclude the string of the header. However, the VBA compiler is not recognizing my If block. I believe my syntax is correct. How can I fix this?
Public Sub iterate_factIDs()
'https://social.msdn.microsoft.com/Forums/office/en-US/79f9d96d-1ec8-48e6-
b7dd-e11901a5c72b/looping-through-excel-filtered-range?forum=exceldev
Sheets("GL").Select
Dim rngC As Range
Dim ws As Worksheet
Set ws = ActiveSheet
For Each rngC In Intersect(ws.UsedRange,
ws.Range("B:B").SpecialCells(xlCellTypeVisible))
'this is the if condition that is not recognized
If rngC.Row <> 1 Then:
'MsgBox ("Found Row: " & rngC.Row)
'want to display all the numeric values in Column 2 after filter
'this also displays the title of the column which is in row 1 column B
MsgBox ("FactID: " & Cells(rngC.Row, 2))
End If
Next rngC
End Sub
The compiler returns "End If without Block If" even though I have an If-Then statement in my code.
Aucun commentaire:
Enregistrer un commentaire