.listrows.add not working

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
304
Office Version
  1. 2016
Platform
  1. Windows
I have been using this code for a couple years with no problem.
This past week it simply does not add a row in my table. No error message but the .listrows.add line is not happening.
Any help to why this is now happening or a fix would be appreciated.

VBA Code:
Sub InsertNewLine()
    Dim Tbl As Object, i As Long
Set Tbl = ActiveSheet.ListObjects(1)    'first table on sheet
With Tbl
    If Not Intersect(Selection, .DataBodyRange) Is Nothing Then
        i = ActiveCell.Row - .HeaderRowRange.Row
        .ListRows.Add (i + 1)
        .DataBodyRange.Cells(i + 1, 3) = .DataBodyRange.Cells(i, 3)
        .DataBodyRange.Cells(i + 1, 5).Select

    End If
End With
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
How about

VBA Code:
Sub jec()
 Dim s
 With ActiveSheet.ListObjects(1)
   Set s = Selection
   If Not Intersect(s, .DataBodyRange) Is Nothing Then
      .ListRows.Add(s.Row).Range(1, 3) = .Range(s.Row, 3)
       Application.Goto .Range(s.Row + 1, 5)
   End If
 End With
End Sub
 
Upvote 0
It stills does not insert a new line in the table.
The rest of the code works as intended
 
Upvote 0
Try to use the real name of the listobject

VBA Code:
ActiveSheet.ListObjects("table name")
 
Upvote 0
Do you by any chance have another table below that table and that other table is wider than your current table ?

1702470424618.png
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,156
Messages
6,123,338
Members
449,098
Latest member
thnirmitha

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