.ListRows.Add doesn't shift my hidden row

KyleSC

New Member
Joined
Dec 30, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I'm having a little issue with the following VBA code interfering with my hidden row(s)

Sub macAddRow()
Dim loTbl As ListObject

Set loTbl = ActiveSheet.ListObjects("Table1")

loTbl.ListRows.Add
End Sub

Here's the problem. Let's say Table1 takes up the space A1:D5. I have data in cells in rows 9, 10, and 11. Row 10 is hidden. When I execute the code, my data in rows 9, 10, and 11 shifts down to rows 10, 11, and 12, but row 10 is still the hidden row. I want it to be row 11 that is hidden. Hopefully the attached before & after code execution images make this problem clear.

I will eventually have multiple tables in this worksheet, and the number of rows in each table will be frequently changing. There will be multiple hidden rows. Is there a small tweak I can make to the code in order for it to work the way I want? Please let me know if there's something you want me to clarify.
 

Attachments

  • Before execution.png
    Before execution.png
    53.2 KB · Views: 11
  • After execution.png
    After execution.png
    59.9 KB · Views: 11

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If you do this manually it behaves as expected? Then macro recorder might provide the right method. My hidden row changed from 3 to 4 which is what I think you're saying should happen. Code line is

Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
 
Upvote 0
Solution
Hmm... I can't remember why I chose .ListRows.Add rather than .Insert Shift. Thanks, that works great!
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top