Add a row below an activebutton, keeping the format without resizing the button

guippezzini

New Member
Joined
Jun 1, 2018
Messages
2
Hi. I would like to click at the "+" button and add an entire blank row below the "button", so I can put a new hour with new value for a specific day. It is important to keep the format, fill color, and to not resize the button (when I insert a row manually, the button gets bigger to the cell below). I've searched the internet a lot and didn't find a good macro to do it.
The new row must not have the "+"button, or + sign.
Thanks!


[TABLE="class: grid, width: 300"]
<tbody>[TR]
[TD]Day[/TD]
[TD]Add[/TD]
[TD]Hour[/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD="align: center"]01[/TD]
[TD="align: center"]+[/TD]
[TD="align: center"]08:00[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]02[/TD]
[TD="align: center"]+[/TD]
[TD="align: center"]08:00[/TD]
[TD="align: center"]4[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]Sum[/TD]
[TD="align: center"]6[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
this example code does not uses buttons.
if you select a cell that contains a "+" this little piece of code will insert a blank line below that line.
Right click on the sheetlabel, select View code and paste this
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count = 1 And Target.Value = "+" Then
        Rows(Target.Row + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End If
End Sub
the sum formula: if you use =SUM(INDIRECT("D2:D"&ROW(D3)))
it automatically adapts to the extra line inserted
 
Upvote 0
Thank you for your answer! I still want to make it work using the button.. If this is not possible I will use your method
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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