Macro - Insert Row with cell merge and formula copy

Eios000

New Member
Joined
May 25, 2021
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Afternoon all,

With much searching occurring around the interwebs I cannot find an answer to this, so here's what I would like to achieve!

Macro InsertRow()

When new row is inserted below the last used row, I need the following to occur within the worksheet "Register".
  1. The cell above the new row in Column A is merged,
  2. The formatting and formula in Column P is copied into the new row, and
  3. All other values apart from the previous two mentioned are cleared
Thanks for your help!

-Kyle.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
The cell above the new row in Column A is merged with what cell(s)? Maybe sample will give clearer picture.
 
Upvote 0
If you want to keep everything line the previous row, you can just copy and paste the previous row. Then clear the contents of new row using

<range>.ClearContents

Then you can merge the cell. I presumed you want to merge column A with previous one like:
Set rngA = Range("A" & <newRow>)
Range(rngA, rngA.Offset(-1)).Merge
 
Upvote 0
The cell above the new row in Column A is merged with what cell(s)? Maybe sample will give clearer picture.
Hey Zot,

I've added some pictures of the intended outcome, hopefully this clarifies what I'm trying to achieve.

-Kyle.
 

Attachments

  • Before Macro.PNG
    Before Macro.PNG
    15.9 KB · Views: 24
  • Macro Used Once.PNG
    Macro Used Once.PNG
    14.2 KB · Views: 24
  • Macro Used Twice.PNG
    Macro Used Twice.PNG
    15.6 KB · Views: 24
Upvote 0
Hey Zot,

I've added some pictures of the intended outcome, hopefully this clarifies what I'm trying to achieve.

-Kyle.
It looks like what I proposed in Post #3

I have no idea the steps you take to fill the table. So, I have no clue where the code need to start from :)
 
Upvote 0
Here is simple semi-auto approach

Select the last populated row and run the macro below. See if this works
VBA Code:
Sub InsertRow()

ActiveCell.EntireRow.Copy ActiveCell.Offset(1)
ActiveCell.Offset(1).Select
ActiveCell.EntireRow.SpecialCells(xlCellTypeConstants, 23).Clear
Set rngA = Range("A" & ActiveCell.Row)
Range(rngA, rngA.Offset(-1)).Merge
rngA.VerticalAlignment = xlCenter

End Sub
 
Upvote 0
Thanks for your help Zot! I ended up not going with the merge option, turns out with other macros this was creating issues.
 
Upvote 0
Thanks for your help Zot! I ended up not going with the merge option, turns out with other macros this was creating issues.
Yes, avoid at all cost using merged cell with macro. Just inviting headache only :)
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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