I'm trying to insert a row above, then go up one to the next visible row in a filtered spreadsheet. Because I want to apply the action to visible rows (which can be spaced randomly), this line of code isn't sufficient:
ActiveCell.Offset(-8, 0)
As I understand it, this tells Excel to move up eight rows (because the cell set I used to record the macro happened to be spaced eight cells apart), not to the next visible row under present filter conditions.
Excerpt of spreadsheet showing that visible data rows are randomly spaced
in this case 6 rows apart but it could be any number.
The macro code:
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(-8, 0).Rows("1:1").EntireRow.Select
I'm looking to replace the last line of code "go up eight rows" with "go up to next visible row, given current data filters".
The filter shows rows where Column R = 0, but I'd prefer a method where I don't incorporate that instruction into the VBA code and just look at the visible data instead of the whole spreadsheet.