Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Insert two rows in one line of code?

I am using Office 2003 on Windows XP.

Presently I have code that inserts two blank rows based on changes in a
criteria column, the insert code (which feeds the appropriate row number from
an array) looks like this:

For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Next lX

The above code is inefficient since it has to perform two separate inserts
every time. Rather than having two separate identical code lines and
therefore doing two separate inserts, isn't there a way to tell it how many
rows to insert and then insert them all in one action and in one line of
code? I'm trying to speed up the insert process.

Could someone please fix my code to do a two line insert in one go?

Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Insert two rows in one line of code?

try this
For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX))..EntireRow.Resize(2).Insert
Next lX



--


Gary


"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

Presently I have code that inserts two blank rows based on changes in a
criteria column, the insert code (which feeds the appropriate row number
from
an array) looks like this:

For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Next lX

The above code is inefficient since it has to perform two separate inserts
every time. Rather than having two separate identical code lines and
therefore doing two separate inserts, isn't there a way to tell it how
many
rows to insert and then insert them all in one action and in one line of
code? I'm trying to speed up the insert process.

Could someone please fix my code to do a two line insert in one go?

Thanks much in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Insert two rows in one line of code?

Thanks Gary.

FYI, this method reduced 5,334 row inserts from 4:00 minutes, to 2:05!
Thanks!

"Gary Keramidas" wrote:

try this
For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX))..EntireRow.Resize(2).Insert
Next lX



--


Gary


"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

Presently I have code that inserts two blank rows based on changes in a
criteria column, the insert code (which feeds the appropriate row number
from
an array) looks like this:

For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Next lX

The above code is inefficient since it has to perform two separate inserts
every time. Rather than having two separate identical code lines and
therefore doing two separate inserts, isn't there a way to tell it how
many
rows to insert and then insert them all in one action and in one line of
code? I'm trying to speed up the insert process.

Could someone please fix my code to do a two line insert in one go?

Thanks much in advance.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Insert two rows in one line of code?

did you also try setting calculation to manual before running the improved
code?

--
Regards,
Tom Ogilvy


"quartz" wrote in message
...
Thanks Gary.

FYI, this method reduced 5,334 row inserts from 4:00 minutes, to 2:05!
Thanks!

"Gary Keramidas" wrote:

try this
For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX))..EntireRow.Resize(2).Insert
Next lX



--


Gary


"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

Presently I have code that inserts two blank rows based on changes in

a
criteria column, the insert code (which feeds the appropriate row

number
from
an array) looks like this:

For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Next lX

The above code is inefficient since it has to perform two separate

inserts
every time. Rather than having two separate identical code lines and
therefore doing two separate inserts, isn't there a way to tell it how
many
rows to insert and then insert them all in one action and in one line

of
code? I'm trying to speed up the insert process.

Could someone please fix my code to do a two line insert in one go?

Thanks much in advance.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Insert two rows in one line of code?

Yes, thanks Tom for that thought, my code includes the following to help
things out:

Application.ScreenUpdating = False
ActiveSheet.DisplayAutomaticPageBreaks = False
Application.Calculation = xlCalculationManual

Thanks.

"Tom Ogilvy" wrote:

did you also try setting calculation to manual before running the improved
code?

--
Regards,
Tom Ogilvy


"quartz" wrote in message
...
Thanks Gary.

FYI, this method reduced 5,334 row inserts from 4:00 minutes, to 2:05!
Thanks!

"Gary Keramidas" wrote:

try this
For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX))..EntireRow.Resize(2).Insert
Next lX



--


Gary


"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

Presently I have code that inserts two blank rows based on changes in

a
criteria column, the insert code (which feeds the appropriate row

number
from
an array) looks like this:

For lX = UBound(saRows) To 1 Step -1
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Rows(saRows(lX)).EntireRow.Insert Shift:=xlDown
Next lX

The above code is inefficient since it has to perform two separate

inserts
every time. Rather than having two separate identical code lines and
therefore doing two separate inserts, isn't there a way to tell it how
many
rows to insert and then insert them all in one action and in one line

of
code? I'm trying to speed up the insert process.

Could someone please fix my code to do a two line insert in one go?

Thanks much in advance.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro code to put series name next to individual line in line grap Otani Charts and Charting in Excel 3 February 23rd 10 07:24 PM
Editing code to insert two rows achidsey Excel Programming 2 August 30th 05 03:14 PM
Code to delete a Line in a another code helmekki[_88_] Excel Programming 1 August 8th 05 01:14 AM
Continue line of VBA code on the next line peacelittleone Excel Programming 9 June 24th 05 07:46 PM
Help with some code to insert rows Gareth[_3_] Excel Programming 2 December 11th 03 10:10 PM


All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"