VBA command button to insert row at bottom of table using active.cell

charliew

Board Regular
Joined
Feb 20, 2018
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Good evening,

I have a table that sometimes i might need to add a row to. I need this row to insert at the bottom of the active cell and still hold the formatting and formulas from the row above it, without the contents of the cell.

I did a record macro as i got fed up trying to figure it out. It works if all i wanted to do was add one row. But i might want to add more than 1 row, but when i click the button again the new row add in the middle of my table and not at the bottom.

Here is my code I'm using.


HTML:
Sub Add_Lines()'' Add_Lines Macro'
'    Rows("19:19").Select    
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove    
Range("A18:T18").Select    
Selection.Copy    
Range("A19:T19").Select    
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False    
Application.CutCopyMode = False    
Range("A18:Q18").Select    
Selection.Copy    
Range("A19:Q19").Select    
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _        
SkipBlanks:=False, Transpose:=False    
Range("B19:D19").Select    
Application.CutCopyMode = False    
Selection.ClearContents
End Sub


ideally, it would be nice if a message box pops up asking how many rows id like to enter...

thanks in advance :)
 
Sorry, I forgot to translate this part:

Check your formulas, only formats and formulas are being copied.
If you don't want to copy formulas, then remove this line:

Code:
Rows(i & ":" & i + n - 1).PasteSpecial Paste:=xlPasteFormulas

If you want to copy validationes, try this:

Code:
Rows(i & ":" & i + n - 1).PasteSpecial Paste:=xlPasteValidation
 
Upvote 0

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.
De acuerdo, avísame si tienes alguna duda (Ok, let me know if you have any doubt)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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