Hello,
My goal is to create a macro that inserts a blank row just above a user-selected cell or row and copies formulas from the selected row into the new inserted row. Only formulas are to be copied, not constants. Cells with constant values in the copied row are left blank in the inserted row.
Code is pretty basic. Here it is:
Sub InsertLine()
Selection.EntireRow.Insert
Selection.Offset(1, 0).EntireRow.copy Selection.EntireRow
Selection.EntireRow.SpecialCells(xlCellTypeConstants).ClearContents
End Sub
This works great in all but one situation.
If the range contains both an activated auto-filter and hidden columns, then the content of the hidden cell on the copied row does not get selected by the copy method and is hence not transferred to the inserted line.
If the range is only auto-filtered or only has hidden columns, then all works good.
I've included a simple workbook with the above code and a simple table i've been using to test this issue.
Testing of AddLine MAcro.xlsm
This behavior is well documented here but no solution is offered.
I haven't found anything else on the web.
This behavior is identical when performing cut-and-paste (ctrl-C/ctrl-V ) operations manually directly from the spread sheet.
So i would say it's not a VBA issue. But the solution may lay with VBA.
Can anyone offer any suggestions or workarounds?
Thanks,
Fred
Bookmarks