Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Insert line every x lines until end of data

Hi,

I am trying to write a macro that will insert a new line after every 5 lines
of data and keep doing this until there are no more lines of data (1,000+
lines).

If anyone could help I would really appreciate it.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Insert line every x lines until end of data


change the column in the lastrow statement to your longest column of data and
the sheet name in the set statement

this may get you started

Sub insertLines()
Dim i As Long
Dim ws As Worksheet
Dim lastrow As Long
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow Step 5
Rows(i).EntireRow.Insert
Next

End Sub
--


Gary


"tiger" wrote in message
...
Hi,

I am trying to write a macro that will insert a new line after every 5 lines
of data and keep doing this until there are no more lines of data (1,000+
lines).

If anyone could help I would really appreciate it.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Insert line every x lines until end of data

another way:

Option Explicit

Sub insertLines()
Dim i As Long
Dim ws As Worksheet
Dim lastrow As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow

If i Mod 5 = 0 Then
Rows(i).EntireRow.Insert
End If
Next
Application.ScreenUpdating = True

End Sub

--


Gary


"tiger" wrote in message
...
Hi,

I am trying to write a macro that will insert a new line after every 5 lines
of data and keep doing this until there are no more lines of data (1,000+
lines).

If anyone could help I would really appreciate it.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Insert line every x lines until end of data

I don't think that either of Gary's macros will work. He has not taken into
account that the number of rows increase as the rows are inserted.

Here is a simplistic one:-

Sheets("Sheet1").Select
Range("A1").Select 'Set range to start point
Do While ActiveCell.Value < ""
ActiveCell.Offset(5, 0).Select
Selection.EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Loop

Regards,

OssieMac


"Gary Keramidas" wrote:

another way:

Option Explicit

Sub insertLines()
Dim i As Long
Dim ws As Worksheet
Dim lastrow As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow

If i Mod 5 = 0 Then
Rows(i).EntireRow.Insert
End If
Next
Application.ScreenUpdating = True

End Sub

--


Gary


"tiger" wrote in message
...
Hi,

I am trying to write a macro that will insert a new line after every 5 lines
of data and keep doing this until there are no more lines of data (1,000+
lines).

If anyone could help I would really appreciate it.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Insert line every x lines until end of data


yes it was late, i should have at least started at the lastrow.

your suggestion is fine.
--


Gary


"OssieMac" wrote in message
...
I don't think that either of Gary's macros will work. He has not taken into
account that the number of rows increase as the rows are inserted.

Here is a simplistic one:-

Sheets("Sheet1").Select
Range("A1").Select 'Set range to start point
Do While ActiveCell.Value < ""
ActiveCell.Offset(5, 0).Select
Selection.EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Loop

Regards,

OssieMac


"Gary Keramidas" wrote:

another way:

Option Explicit

Sub insertLines()
Dim i As Long
Dim ws As Worksheet
Dim lastrow As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow

If i Mod 5 = 0 Then
Rows(i).EntireRow.Insert
End If
Next
Application.ScreenUpdating = True

End Sub

--


Gary


"tiger" wrote in message
...
Hi,

I am trying to write a macro that will insert a new line after every 5
lines
of data and keep doing this until there are no more lines of data (1,000+
lines).

If anyone could help I would really appreciate it.







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 to insert blank line when lines sum to zero TCoats Excel Discussion (Misc queries) 0 July 2nd 07 05:08 PM
How do I insert a row between each line of data in Excel? Jacobo Excel Discussion (Misc queries) 4 June 25th 07 11:44 PM
Possible to insert cell data in the middle of line of text? Bob Smith Excel Worksheet Functions 6 July 29th 05 08:14 PM
Formatting lines between data points in a line chart ltanner Charts and Charting in Excel 2 March 13th 05 05:12 AM
How do i insert lines into a worksheet depending on if data exist. Nutter Excel Programming 0 February 9th 05 03:23 PM


All times are GMT +1. The time now is 03:33 PM.

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

About Us

"It's about Microsoft Excel"