View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
okrob okrob is offline
external usenet poster
 
Posts: 142
Default Adding blank rows every 3rd row

I see what you have there Bob...
When I ran it on about 1500 rows, it stopped inserting at about row
1500.
Shoulda seen that before shootin off my lip.. :0)
Rob



Bob Phillips wrote:
I went bottom up for a very good reason, if you insert rows in a block of
data, you won't process it all, it will terminate before the last row
(because these rows get shifted down).

Also FIRST_ROW is part of the code, I just forgot to include it

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Const FIRST_ROW As Long = 2 '<=== set to 2,1, or 0
Dim i As Long
Dim iLastRow As Long
Dim cell As Range
Dim sh As Worksheet

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow - FIRST_ROW To 2 Step -3
Rows(i).Insert
Next i

End With

End Sub

it determines where the blank is inserted, and is to facilitate tuning.


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"okrob" wrote in message
oups.com...
To partially plagarize you Bob, she's wanting this to show every 3rd
row starting at the top as a blank, with a header row...

liz25mc,
Change this: For i = iLastRow - (iLastRow Mod 3) To 2 Step -3
To this: For i = 5 To (iLastRow - (iLastRow Mod 3)) Step 3

ALSO, in Bob's code, you don't need these lines, unless you're using
them somewhere else...

Const FIRST_ROW As Long = 0 '<=== set to 2,1, or 0
Dim cell As Range
Dim sh As Worksheet

The Const TEST_COLUMN As String = "A" sets the column your looking at.
So, if your data is in column B, change that to B, etc...

Rob


liz25mc wrote:
Hi Bob,

Thanks for the code. I'm not sure I understand what:
Const TEST_COLUMN as String = "A" does.

The first row iin the spreadsheet contains field names (sorry, I should
have
mentioned that in my previous post).
When I run the code I get two rows and then a blank on the first three
rows,
and then a blank after every third row in the rest of the spreadsheet.
Wondering what I am doing wrong, and hope you can set me straight on what
changes I need to make to the code.

Thanks again.

"Bob Phillips" wrote:

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Const FIRST_ROW As Long = 0 '<=== set to 2,1, or 0
Dim i As Long
Dim iLastRow As Long
Dim cell As Range
Dim sh As Worksheet

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow - (iLastRow Mod 3) To 2 Step -3
Rows(i).Insert
Next i

End With

End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"liz25mc" wrote in message
...
Can someone provide coding to add a blank row every 3rd row in Excel
2003.

Thanks in advance!