Inserting #of rows based on dcount

Lisa

Board Regular
Joined
Apr 28, 2002
Messages
80
Please forgive another newbie question.

I'm trying to insert a specific number of rows based on a dcount return. Based on recording, the code for insertion is

Selection.EntireRow.Insert

Using F2 for insert shows me this:

Insert([shift])

I don't understand what this is telling me. Is there a way to put a variable in to tell the routine how many rows to insert? Such as the range name where the dcount is? I've attempted several things, but think I'm misunderstanding the required syntax.

Thanks for any help.
Lisa
 
Nate -

I missed your location on that last post. I'm in the other "polis"... Indianapolis. My brother lives up your way in Lakeville,MN.

Thanks again for all of your help
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
On 2002-04-30 10:48, NateO wrote:
I think I've botched the question. Do you mean 'insert91' is a single cell and instead of inserting single cells, you want a row. Try:

Code:
Sub addb600()
Dim i As Long, n As Long
i = Sheets("information").Range("bcount").Value
For n = 1 To i
Sheets("Detail").Range("insert91").EntireRow.Insert
Next n

End Sub

Getting warmer?

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-30 10:49

Greetings from another midwesterner.

To make the working code even more efficient, remove the i = 1 to n loop and insert all the rows in one shot.

Sub addb600()
Dim i As Long, i2 As Long

i = Sheets("information").Range("bcount").Value
i2 = Sheets("Detail").Range("insert91").Row
Rows(i2).Resize(i).Insert

End Sub

Untested, but should work. (I am assuming you've activated the correct sheet.)

Bye,
Jay

EDIT: If the number of rows is small, this won't save any time that could be noticed. I just wanted to pass along the .Resize option, which I've just learned and have found useful.
This message was edited by Jay Petrulis on 2002-04-30 11:45
 
Upvote 0
Thanks, Jay for the code. I'll give it a try ... probably next week when I try to clean up after myself... right now I'm just trying to get this application to work for month end.

Lisa
 
Upvote 0
I took the liberty, it works. Faster than the loop, which as Jay mentioned, is nicer in the scheme of large procedures.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-30 12:43
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,016
Members
448,543
Latest member
MartinLarkin

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