LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default insert rows by vba

Dave,
When you say it "makes life easier..."
is that because when it goes forward the rows start getting offset in an
increasing count from the count originally showing? I.e., once I figured out
why I wasn't getting it to work, I increased my 'to' from 4 to 20, and by the
last one it'd jumped up one from the 24-3 spacing I wanted to a 21-24
spacing. (I hope that makes sense.)

I've changed it to go backwards, to see how it works. I'll let you know once
it finishes the initial run. It looks as though it'll be a while as my home
system is 8 years old, and runs likes a turtle, snail's pace.

"Dave Peterson" wrote:

When you're inserting/deleting rows, it sometimes make life much easier to work
from the bottom up:

This:
For i = 1 To 40 Step 8

Becomes:
For i = 40 to 1 step -8

I'm not sure how that fits into the rest of your code, though.

Maybe...

Sub InsertRow()
Dim MyRange As Range
dim i as long

Set MyRange = Nothing
On Error Resume Next
Set MyRange = Application.InputBox(Prompt:="Pick the row to start at.", _
Type:=8).Rows(1)
on error goto 0

if myRange is nothing then
exit sub
end if

Workbooks.Application.ScreenUpdating = False
For i = myrange.row To 4 Step -8
rows(i).EntireRow.Insert
Next i

End Sub

SteveDB1 wrote:

Hi all.
Hope everyone is enjoying their respective memorial day weekend.

I have a large file that I've made, and want to insert a series of rows by
vba.
I thought the following would work, but I've missed something, and I cannot
quite figure out where I've gone wrong.
I've tried a number of variations, and nothing works. I.e., they'll either
only insert one row, but no more, or no rows at all.
I'd thought that some variation of:

for i = 1 to n step X would work, but it hasn't.

Sub InsertRow()
'
' InsertRow Macro
' make this a auto-insert macro to insert my rows for me.
' it'll definitely save time.

Dim MyRange As Range

Set MyRange = Nothing

On Error Resume Next
Set MyRange = Application.InputBox(Prompt:="Pick the row to start at.",
Type:=8).Rows(1)

Workbooks.Application.ScreenUpdating = False
For i = 1 To 4 Step 8

MyRange(i).EntireRow.Insert (xlShiftDown)

Next i

'On Error GoTo 0
'If MyRange Is Nothing Then
'Exit Sub 'user hit cancel.
'End If


Savechanges = True

End Sub


--

Dave Peterson

 
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
insert rows in a worksheet that do not change adjoining rows craigandmel Excel Discussion (Misc queries) 2 April 29th 08 10:26 PM
Insert rows: Formats & formulas extended to additonal rows Twishlist Excel Worksheet Functions 0 October 22nd 07 04:23 AM
Insert page breaks every 50 rows but do not include hidden rows Martin[_21_] Excel Programming 5 March 12th 07 05:10 PM
How do I insert blank rows between rows in completed worksheet? bblue1978 Excel Discussion (Misc queries) 1 October 26th 06 07:02 PM
Copy Rows and insert these rows before a page break AQ Mahomed Excel Programming 0 June 8th 04 09:09 AM


All times are GMT +1. The time now is 06:17 AM.

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"