Macro Insert Row Below Copy Formulas and Formats

Solon Aquila

New Member
Joined
Sep 24, 2011
Messages
25
Greetings,

I have a spreadsheet in which we sometimes need to insert a row right in the middle of a bunch of filled-out rows.
I'd like to have the inserted row contain the same formulas and conditional formats as the other rows, but not copy the text/values.

I've tried a few things but can't seem to copy/paste just the formulas/conditional formats.
I've seen a few suggestions (PasteSpecial Paste:xlFormats or something) but just don't know enough to make them work.

here's what I'm using now:

Sub Copy_One_Row_Below()
With Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row, 16))
.Copy
.Insert shift:=xlDown
Application.CutCopyMode = False

End With
Cells(ActiveCell.Row + 1, 2) = "=" & Cells(ActiveCell.Row, 2).Address & "+1"
End Sub

It works as long as I don't mind the data being pasted as well.

Any suggestions?

Thanks!
Solon
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Greetings,

I have a spreadsheet in which we sometimes need to insert a row right in the middle of a bunch of filled-out rows.
I'd like to have the inserted row contain the same formulas and conditional formats as the other rows, but not copy the text/values.

I've tried a few things but can't seem to copy/paste just the formulas/conditional formats.
I've seen a few suggestions (PasteSpecial Paste:xlFormats or something) but just don't know enough to make them work.

here's what I'm using now:

Sub Copy_One_Row_Below()
With Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row, 16))
.Copy
.Insert shift:=xlDown
Application.CutCopyMode = False

End With
Cells(ActiveCell.Row + 1, 2) = "=" & Cells(ActiveCell.Row, 2).Address & "+1"
End Sub

It works as long as I don't mind the data being pasted as well.

Any suggestions?

Thanks!
Solon

Untested by maybe:

Code:
Sub Copy_One_Row_Below()
With Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row, 16))
.Copy
.Insert shift:=xlDown
.ClearContents
Application.CutCopyMode = False

End With
Cells(ActiveCell.Row + 1, 2) = "=" & Cells(ActiveCell.Row, 2).Address & "+1"
End Sub
 
Upvote 0
John,

Thanks for the quick reply and darn, so close. I got the conditional formats, but not the formulas.

I tried moving the 'clear contents' down to after the With and Excel got mad at me. :)

Hmm... .PasteSpecial xlPasteFormulas (and xlPasteFormats) gave me TWO rows.

This is an intriguing one.
 
Upvote 0
John,

Thanks for the quick reply and darn, so close. I got the conditional formats, but not the formulas.

I tried moving the 'clear contents' down to after the With and Excel got mad at me. :)

Hmm... .PasteSpecial xlPasteFormulas (and xlPasteFormats) gave me TWO rows.

This is an intriguing one.

Maybe:

Code:
Sub Copy_One_Row_Below()
With Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row, 16))
.Offset(1).Insert shift:=xlDown
.Copy
.Offset(1).PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
.Offset(1).PasteSpecial xlPasteFormats
Application.CutCopyMode = False

End With
Cells(ActiveCell.Row + 1, 2) = "=" & Cells(ActiveCell.Row, 2).Address & "+1"
End Sub
 
Upvote 0
I thought I had posted a Thank You to this, but apparently not.

Thanks for your time and help, it's all fixed now!

Solon
 
Upvote 0
Maybe:

Code:
Sub Copy_One_Row_Below()
With Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row, 16))
.Offset(1).Insert shift:=xlDown
.Copy
.Offset(1).PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
.Offset(1).PasteSpecial xlPasteFormats
Application.CutCopyMode = False

End With
Cells(ActiveCell.Row + 1, 2) = "=" & Cells(ActiveCell.Row, 2).Address & "+1"
End Sub

Can this be achieved with Worksheet_Change?
 
Upvote 0
Hi Champions
I have one sheet in excel where I need to add rows below the row 12 using a button.
now the macro should work in a way that first click on the button inserts below row 12 copying only the formats and formulae from row 12 to 13.
next click should do the same above step but should insert below 13 and so on.
I am trying to make a Rate Calculator in which I need to have a dynamic sheet where user can add any number of entries they want by clicking this add button

I hope someone will be able to assist me here
Thanks
Imran
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,012
Members
449,280
Latest member
Miahr

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