VBA - Insert row before the Total row in my table

JoshLyman

New Member
Joined
Jan 11, 2023
Messages
35
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have the below table on a sheet called 3 - OTJ LOG which has a Total row at the bottom, and will always be filled (I just don't want to have to add many many unnecessary rows, without knowing how many).

DRAFT - OTJ Log - v0.1.xlsm
BC
9DateOTJ hrs
1025/08/20233
1126/08/20235
1227/08/20236
1328/08/20236
1429/08/20233
1530/08/20235
1631/08/20237
1701/09/20233
18Total38
3 - OTJ LOG
Cell Formulas
RangeFormula
C18C18=SUBTOTAL(109,[OTJ hrs])


Is there a way (using VBA) for me to have an a button which the user clicks and it adds a new row into this table before the Total row?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
All the user really needs to do is hit <Tab> when they are in the last cell of the table.
But if you really need a macro do to do it then try this:

VBA Code:
Sub AddRowToTable()

    Dim tbl As ListObject
    
    Set tbl = Range("tblOTJ").ListObject    ' <---- Change to Actual Table name
    
    tbl.ListRows.Add
    
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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