Hello,
I have code below, that currently targets and inserts a blank row above whatever I have set to Autofiltered.
In this case I have already manually set the Autofilter.
Instead of ABOVE what it Autofiltered, I was wondering if there is a way to insert a row BELOW what is Autofiltered.
Example with Filters Applied:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A (Filtered by Date)[/TD]
[TD]B (Filtered by Type)[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]Fruit[/TD]
[TD]Price[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Apple[/TD]
[TD].99[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Banana[/TD]
[TD].50[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Clementine[/TD]
[TD].25[/TD]
[/TR]
</tbody>[/TABLE]
Example After Code Run: This example negates other data that might exist after Autofilter is turned off.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A (Filtered by Date)[/TD]
[TD]B (Filtered by Type)[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]Fruit[/TD]
[TD]Price[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Apple[/TD]
[TD].99[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Banana[/TD]
[TD].50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Clementine[/TD]
[TD].25[/TD]
[/TR]
</tbody>[/TABLE]
Desired Effect: Lines inserted below what is Autofiltered instead of above.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A (Filtered by Date)[/TD]
[TD]B (Filtered by Type)[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]Fruit[/TD]
[TD]Price[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Apple[/TD]
[TD].99[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Banana[/TD]
[TD].50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Clementine[/TD]
[TD].25[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have code below, that currently targets and inserts a blank row above whatever I have set to Autofiltered.
In this case I have already manually set the Autofilter.
Instead of ABOVE what it Autofiltered, I was wondering if there is a way to insert a row BELOW what is Autofiltered.
Code:
Sub InsRws()
' *This code assumes Autofilter is already applied
Dim Rng As Range
Set Rng = Intersect(Columns(1), ActiveSheet.UsedRange).SpecialCells(xlCellTypeVisible)
Range("A1").AutoFilter
Rng.EntireRow.Insert
Range("A1").Select
' *Delete Excess Header blank row created by code
Rows("1:1").Select
Selection.Delete Shift:=xlUp
' *Insert Blank Line in row 2 for empty selection
Rows("2:2").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
Example with Filters Applied:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A (Filtered by Date)[/TD]
[TD]B (Filtered by Type)[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]Fruit[/TD]
[TD]Price[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Apple[/TD]
[TD].99[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Banana[/TD]
[TD].50[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Clementine[/TD]
[TD].25[/TD]
[/TR]
</tbody>[/TABLE]
Example After Code Run: This example negates other data that might exist after Autofilter is turned off.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A (Filtered by Date)[/TD]
[TD]B (Filtered by Type)[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]Fruit[/TD]
[TD]Price[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Apple[/TD]
[TD].99[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Banana[/TD]
[TD].50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Clementine[/TD]
[TD].25[/TD]
[/TR]
</tbody>[/TABLE]
Desired Effect: Lines inserted below what is Autofiltered instead of above.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]A (Filtered by Date)[/TD]
[TD]B (Filtered by Type)[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]Fruit[/TD]
[TD]Price[/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Apple[/TD]
[TD].99[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Banana[/TD]
[TD].50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/15/2019[/TD]
[TD]Clementine[/TD]
[TD].25[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]