Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Little pete
 
Posts: n/a
Default auto insert blank line

wanting to auto insert a blank line every 'x' number of lines down the s/s.
for the example 'x' can be every 4th line

cheers pete
  #2   Report Post  
Paul B
 
Posts: n/a
Default

Pete, here is some code that will do it,

Sub testme()
'will add a row after every 4th row
'Original code by: Dave Peterson
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = 5 To LastRow Step 4
If myRng Is Nothing Then
Set myRng = .Cells(iCtr, "A")
Else
Set myRng = Union(.Cells(iCtr, "A"), myRng)
End If
Next iCtr
End With

If myRng Is Nothing Then
'do nothing
Else
myRng.EntireRow.Insert
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Little pete" wrote in message
...
wanting to auto insert a blank line every 'x' number of lines down the

s/s.
for the example 'x' can be every 4th line

cheers pete



  #3   Report Post  
run, I've got the keys
 
Posts: n/a
Default

Paul,
I've attempted to use your script to insert a line every other row, but have
not been successful. I can alter it to insert a line every two rows, but
when I change line "For iCtr = 5 To LastRow Step 4" to "For iCtr = 2 To
LastRow Step 1" my table disappears.

Any suggestions?

Thank you,
Brian

"Paul B" wrote:

Pete, here is some code that will do it,

Sub testme()
'will add a row after every 4th row
'Original code by: Dave Peterson
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = 5 To LastRow Step 4
If myRng Is Nothing Then
Set myRng = .Cells(iCtr, "A")
Else
Set myRng = Union(.Cells(iCtr, "A"), myRng)
End If
Next iCtr
End With

If myRng Is Nothing Then
'do nothing
Else
myRng.EntireRow.Insert
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Little pete" wrote in message
...
wanting to auto insert a blank line every 'x' number of lines down the

s/s.
for the example 'x' can be every 4th line

cheers pete




  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

If you scroll down to the bottom of your worksheet, you'll see the table. Since
you used a step of 1, it saw the whole table as a giant range (instead of
individual cells). And inserted as many rows as there are rows in your table.

If you want to insert a row between each row (I wouldn't do this), you could use
this (that works from the bottom up):

Option Explicit
Sub testme2()
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = LastRow To 2 Step -1
.Rows(iCtr).Insert
Next iCtr
End With
End Sub

The reason I wouldn't do this is that those blank rows really mess up things
like autofilter, charts, pivottables.

If you agree (and come to your senses <vbg), maybe just doubling the rowheight
would be sufficient.

You could use something like:

Option Explicit
Sub testme2A()
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
.UsedRange.Rows.AutoFit
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = LastRow To 2 Step -1
.Rows(iCtr).RowHeight = .Rows(iCtr).RowHeight * 2
Next iCtr
End With
End Sub

run, I've got the keys wrote:

Paul,
I've attempted to use your script to insert a line every other row, but have
not been successful. I can alter it to insert a line every two rows, but
when I change line "For iCtr = 5 To LastRow Step 4" to "For iCtr = 2 To
LastRow Step 1" my table disappears.

Any suggestions?

Thank you,
Brian

"Paul B" wrote:

Pete, here is some code that will do it,

Sub testme()
'will add a row after every 4th row
'Original code by: Dave Peterson
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = 5 To LastRow Step 4
If myRng Is Nothing Then
Set myRng = .Cells(iCtr, "A")
Else
Set myRng = Union(.Cells(iCtr, "A"), myRng)
End If
Next iCtr
End With

If myRng Is Nothing Then
'do nothing
Else
myRng.EntireRow.Insert
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Little pete" wrote in message
...
wanting to auto insert a blank line every 'x' number of lines down the

s/s.
for the example 'x' can be every 4th line

cheers pete





--

Dave Peterson
  #5   Report Post  
run, I''ve got the keys
 
Posts: n/a
Default

Thanks Dave, that worked out great!

"Dave Peterson" wrote:

If you scroll down to the bottom of your worksheet, you'll see the table. Since
you used a step of 1, it saw the whole table as a giant range (instead of
individual cells). And inserted as many rows as there are rows in your table.

If you want to insert a row between each row (I wouldn't do this), you could use
this (that works from the bottom up):

Option Explicit
Sub testme2()
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = LastRow To 2 Step -1
.Rows(iCtr).Insert
Next iCtr
End With
End Sub

The reason I wouldn't do this is that those blank rows really mess up things
like autofilter, charts, pivottables.

If you agree (and come to your senses <vbg), maybe just doubling the rowheight
would be sufficient.

You could use something like:

Option Explicit
Sub testme2A()
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
.UsedRange.Rows.AutoFit
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = LastRow To 2 Step -1
.Rows(iCtr).RowHeight = .Rows(iCtr).RowHeight * 2
Next iCtr
End With
End Sub

run, I've got the keys wrote:

Paul,
I've attempted to use your script to insert a line every other row, but have
not been successful. I can alter it to insert a line every two rows, but
when I change line "For iCtr = 5 To LastRow Step 4" to "For iCtr = 2 To
LastRow Step 1" my table disappears.

Any suggestions?

Thank you,
Brian

"Paul B" wrote:

Pete, here is some code that will do it,

Sub testme()
'will add a row after every 4th row
'Original code by: Dave Peterson
Dim iCtr As Long
Dim LastRow As Long
Dim myRng As Range
With ActiveSheet
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set myRng = Nothing
For iCtr = 5 To LastRow Step 4
If myRng Is Nothing Then
Set myRng = .Cells(iCtr, "A")
Else
Set myRng = Union(.Cells(iCtr, "A"), myRng)
End If
Next iCtr
End With

If myRng Is Nothing Then
'do nothing
Else
myRng.EntireRow.Insert
End If
End Sub



--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Little pete" wrote in message
...
wanting to auto insert a blank line every 'x' number of lines down the
s/s.
for the example 'x' can be every 4th line

cheers pete




--

Dave Peterson

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 Line Insert Frantic Excel-er Excel Discussion (Misc queries) 4 March 20th 06 11:08 PM
When sorting info in columns, can I make it insert blank line bet. nanalehew Excel Worksheet Functions 2 March 12th 05 04:36 PM
Insert Line Macro Spyder Excel Discussion (Misc queries) 1 March 3rd 05 12:17 AM
Cell set to wrap text and blank line -- fix? Fred Holmes Excel Discussion (Misc queries) 0 January 25th 05 07:10 PM
Challenging Charting C TO Charts and Charting in Excel 0 January 17th 05 06:57 PM


All times are GMT +1. The time now is 02:59 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"