Best way to use a macro to insert new rows

John T

Board Regular
Joined
Nov 28, 2013
Messages
145
Office Version
  1. 365
Platform
  1. Windows
I have a workbook that has data in range A5:J54.
Sometimes a row will need to be added if that range is full but only for columns A:J.
I'm not sure if its best to have a button that just inserts a new row every time its pressed below the last entry in that row or to have a button that when pressed asks the user how many rows they would like to add.
Could somebody give me a code for the best option please.

Currently in row 55 and below i have fixed data so this will move down when rows are inserted. for example in cell A55 i have the word "Bodyshop". In other cells i have sub totals.

Many Thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
There are several ways to do this and the most appropriate is dependant on what the user is required to do immediately afterwards

Q1 Is the inserted row an empty row without any formatting or formulas ?

Sometimes a row will need to be added if that range is full but only for columns A:J
Q2 What is the reason for inserting only A:J rather than the whole row ?

Q3 How will the user use the newly-inserted row ?
-eg manual input into every cell, etc ??

Q4 Why would it be helpful to the user to have multiple rows inserted ?
 
Last edited:
Upvote 0
Thanks for replying.

Q1 There is a formula in column J (=SUM(D54:I54)-C54). At the moment if i highlight cells A55:J55 and right click, insert row. That does what i want and keeps the formula.
Q2 I have fixed data to the right and below this cell range. The data to the right i don't want to move down.
Q3 Manually input data
Q4 Currently they have the 50 rows between A5:J54 to enter data. Occasionally they need extras rows if there is more data. I want them to be able to click a button and it to add an additional row if needed.
 
Upvote 0
Is this what you want?
- code looks for cell with value bodyshop ( case insensitive search ) and inserts row above (A:J only) with formula in column J only

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
51
BEFORE
0​
FORMULA in J
52
0​
=SUM(D52:I52)-C52
53
1​
3​
5​
7​
9​
11​
13​
15​
17​
67​
=SUM(D53:I53)-C53
54
2​
4​
6​
8​
10​
12​
14​
16​
18​
72​
=SUM(D54:I54)-C54
55
BodyShopetcetcetc
Sheet: Sheet3

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
51
AFTER 1
0​
FORMULA in J
52
0​
=SUM(D52:I52)-C52
53
1​
3​
5​
7​
9​
11​
13​
15​
17​
67​
=SUM(D53:I53)-C53
54
2​
4​
6​
8​
10​
12​
14​
16​
18​
72​
=SUM(D54:I54)-C54
55
0​
=SUM(D55:I55)-C55
56
BodyShopetcetcetc
Sheet: Sheet3

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
51
AFTER 2
0​
FORMULA in J
52
0​
=SUM(D52:I52)-C52
53
1​
3​
5​
7​
9​
11​
13​
15​
17​
67​
=SUM(D53:I53)-C53
54
2​
4​
6​
8​
10​
12​
14​
16​
18​
72​
=SUM(D54:I54)-C54
55
0​
=SUM(D55:I55)-C55
56
0​
=SUM(D56:I56)-C56
57
BodyShopetcetcetc
Sheet: Sheet3


Code
Code:
Sub InsertRow()
    With ActiveSheet.Range("A:A").Find("bodyshop", MatchCase:=False, LookAt:=xlWhole)
        .Resize(, 10).Insert Shift:=xlDown
        .Offset(-2, 9).Copy .Offset(-1, 9)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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