Insert Variable Number of Rows

Godfreyyy

New Member
Joined
Feb 3, 2015
Messages
2
Hi there, I have been trawling the internet and am having great difficulty in finding an answer to my problem.

I have code that looks at 6 counts to find the maximum, and that works perfectly:

Maximum = (Application.WorksheetFunction.Max(Count1, Count2, Count3, Count4, Count5, Count6))

What I want to do with this maximum is insert that many rows into a different worksheet. I have the following code, however this does not work:

If Maximum > 5 Then
Rows("27:" & (Maximum - 5)).Select
Selection.Insert Shift:=xlDown
End If


(The "-5" is here as there are already 5 rows ready to be used)

For example, if my maximum was 38 it would insert rows between row 27 and row 38, it would not insert 38 rows. Also, if my maximum was 22 it would insert rows between row 22 and row 27, not insert 22 rows.

What do I need to change in order to make this work how it was intended?

Hope I have explained this clearly, TIA :)
 
Last edited:

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,914
Office Version
  1. 365
Platform
  1. Windows
For example, if my maximum was 38 it would insert rows between row 27 and row 38

Not the way you have written it. Because you are subtracting 5 from Maximum, it will delete blank rows between 27 and 33.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,364
Messages
5,595,721
Members
414,013
Latest member
tnobbs

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