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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,618
Office Version
  1. 2016
Platform
  1. Windows
The cell above the new row in Column A is merged with what cell(s)? Maybe sample will give clearer picture.
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,618
Office Version
  1. 2016
Platform
  1. Windows
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
 

Eios000

New Member
Joined
May 25, 2021
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
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: 5
  • Macro Used Once.PNG
    Macro Used Once.PNG
    14.2 KB · Views: 5
  • Macro Used Twice.PNG
    Macro Used Twice.PNG
    15.6 KB · Views: 5

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,618
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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 :)
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,618
Office Version
  1. 2016
Platform
  1. Windows
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
 

Eios000

New Member
Joined
May 25, 2021
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Thanks for your help Zot! I ended up not going with the merge option, turns out with other macros this was creating issues.
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,618
Office Version
  1. 2016
Platform
  1. Windows
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 :)
 

Forum statistics

Threads
1,141,606
Messages
5,707,360
Members
421,503
Latest member
Rickys03

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
Top