Using a Command Button to add new grouped rows with formatting, formulas, and keeping groups at the end of a growing table?

adams3853

New Member
Joined
Jul 14, 2021
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Suuuuper fresh to VBA here.

I've got a table that has many grouped rows all individually under their main banner row that I use for project management that has multiple rounds per project (hence grouped & banner rows). I am trying to add a "Add New Audit" button that adds a new chunk of rows (5 rows, 4 grouped below 1) new projects to the end of the table without having to manually copy and paste the project entry fields. I've included a screenshot of the table I'm working with, and hopefully someone can help with some base code as the code I've gotten thus far towards adding new rows at the end is from other responses that aren't exactly what I need. Namely, they only copy 1 line's formatting and requires the user to know the row to input, whereas I want it to just tack it on to the end.

Here's what I've got:
Private Sub CommandButton1_Click()
Dim rowNum As Long
On Error Resume Next
rowNum = Application.InputBox(Prompt:="Enter Row Number to Add a Row Above:", _
Title:="Add New Row", Type:=1)
Rows(rowNum).Insert Shift:=xlDown
If Err.Number > 0 Then GoTo errH
Range("A" & rowNum - 1).Resize(, 2).Copy Range("A" & rowNum)
Range("D" & rowNum - 1).Resize(, 9).Copy Range("D" & rowNum)
Range("U" & rowNum - 1).Resize(, 7).Copy Range("U" & rowNum)
errH:
End Sub

Thanks for the help!

Also of note, N is the final column in the table, shown at the end of the snip provided.
audit table snip.JPG


Thanks in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Can you post a copy of your data using the XL2BB tool? This will make it MUCH easier to provide and test a solution.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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