looking for some solutions? You are welcome.

SOLVED: VBA Excel insert row to filtered Rows based on Criteria


I'm trying to figure out what's wrong with my code. I'm attempting to filter based on column L2 to the last row and add breaks based on criteria changes from A2 to the last row of the filtered column. But it's running for the hidden rows as well. I'm thinking it's something simple I'm missing but any help or push in the right direction would be greatly appreciated!

Here is my code:

ActiveSheet.Range("A1:O" & lr).AutoFilter Field:=12, Criteria1:="Article State Change"
Set rng = Range("A2:A" & lr).SpecialCells(xlCellTypeVisible)
    irow = rng.Row
    icol = rng.Column
If Cells(irow + 1, icol) <> Cells(irow, icol) Then
   Cells(irow + 1, icol).EntireRow.Insert shift:=xlDown
   Cells(irow + 1, icol).EntireRow.Interior.Color = RGB(192, 192, 192)
   irow = irow + 2
   irow = irow + 1
End If
Loop While Not Cells(irow, icol).Text = ""

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots

No comments: