I have a code that adds rows on my table, it works like this.
Copy entire row based on current cell location (Red row).
Then paste it below the current cell location by adding rows, not just copying the data
Error im getting: Error 1004 - Cannot move cells in a table or filtered range
The problem is, I can't get this code to work when my table has filters, how do I do this without breaking my current code?
My code:
Sub INSERT_ROWS()
Application.ScreenUpdating = False
Dim MyTable As Object
Dim RowsToAdd As Long
RowsToAdd = Worksheets("CC").Range("B18") 'Where i get the number of rows to be added
Set MyTable = ActiveSheet.ListObjects(1)
If RowsToAdd > 0 Then
If Not Intersect(Selection, MyTable.DataBodyRange) Is Nothing Then
Dim SelectedRow As Long
SelectedRow = Intersect(Selection, MyTable.DataBodyRange).Row - MyTable.HeaderRowRange.Row
Dim RowCounter As Long
For RowCounter = SelectedRow To SelectedRow + RowsToAdd - 2 'To place rows bellow current cell location
MyTable.ListRows.Add Position:=RowCounter + 1
MyTable.ListRows(RowCounter).Range.Copy Destination:=MyTable.ListRows(RowCounter + 1).Range
Next RowCounter
End If
End If
Application.ScreenUpdating = True
End Sub