Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default insert a row for every 20,000 th row?

Hi all,

Jsut wondering whether theres a worksheet function or code that could
automatically insert a row for every 20,000 row? or just every X
row??

Thanks for your help :D

Elaine.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default insert a row for every 20,000 th row?


Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Const INSERT_ROW As Long = 5 '<=== CHANGE TO SUIT
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

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

End With

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"elaine" wrote in message
oups.com...
Hi all,

Jsut wondering whether theres a worksheet function or code that could
automatically insert a row for every 20,000 row? or just every X
row??

Thanks for your help :D

Elaine.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default insert a row for every 20,000 th row?

Thanks Bob!
It does exactly what i wanted to!

Thanks so much!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default insert a row for every 20,000 th row?

Elaine,
Adjust as needed:

Dim i As Long

Const ROWJUMP As Long = 20000

For i = 1 To Rows.Count Step ROWJUMP
Rows(i & ":" & i).Insert Shift:=xlDown
'Just to see where rows added
Rows(i & ":" & i).Interior.ColorIndex = 10
Next

NickHK

"elaine" wrote in message
oups.com...
Hi all,

Jsut wondering whether theres a worksheet function or code that could
automatically insert a row for every 20,000 row? or just every X
row??

Thanks for your help :D

Elaine.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default insert a row for every 20,000 th row?

Thank you guys, they work perfectly. Just wondering is there a way I
can insert X rows every Y rows?

Thanks for your help :)

elaine.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default insert a row for every 20,000 th row?

Elaine,
Try this:

Private Sub CommandButton1_Click()
RowInsertion Range("A10"), 100, 10
End Sub

Private Sub RowInsertion(argStartCell As Range, RowsToJump As Long, Optional
RowsToInset As Long = 1)
Dim i As Long

For i = argStartCell.Row To Rows.Count Step RowsToJump
Rows(i & ":" & i + RowsToInset - 1).Insert Shift:=xlDown
'Just to see where rows added
Rows(i & ":" & i + RowsToInset - 1).Interior.ColorIndex = 10
Next

End Function

NickHK

"elaine" wrote in message
oups.com...
Thank you guys, they work perfectly. Just wondering is there a way I
can insert X rows every Y rows?

Thanks for your help :)

elaine.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default insert a row for every 20,000 th row?

Hi NickHK,

your code is taking a long time to run, i guess it is trying to add
rows to the whole spreadsheet (ie ~1 Million rows). Is it possible if
it could jsut add rows to the range that has data??

Thanks very much.
Elaine.


On 30 Apr, 11:29, "NickHK" wrote:
Elaine,
Try this:

Private Sub CommandButton1_Click()
RowInsertion Range("A10"), 100, 10
End Sub

Private Sub RowInsertion(argStartCell As Range, RowsToJump As Long, Optional
RowsToInset As Long = 1)
Dim i As Long

For i = argStartCell.Row To Rows.Count Step RowsToJump
Rows(i & ":" & i + RowsToInset - 1).Insert Shift:=xlDown
'Just to see where rows added
Rows(i & ":" & i + RowsToInset - 1).Interior.ColorIndex = 10
Next

End Function

NickHK

"elaine" wrote in message

oups.com...



Thank you guys, they work perfectly. Just wondering is there a way I
can insert X rows every Y rows?


Thanks for your help :)


elaine.- Hide quoted text -


- Show quoted text -



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default insert a row for every 20,000 th row?

Private Sub RowInsertion(argStartCell As Range, RowsToJump As Long, Optional
RowsToInset As Long = 1)
Dim i As Long

For i = argStartCell.Row To Cells(Rows.Count,
argStartCell.Column).End(xlUp).Row Step RowsToJump
Rows(i & ":" & i + RowsToInset - 1).Insert Shift:=xlDown
'Just to see where rows added
Rows(i & ":" & i + RowsToInset - 1).Interior.ColorIndex = 10
Next


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"elaine" wrote in message
ups.com...
Hi NickHK,

your code is taking a long time to run, i guess it is trying to add
rows to the whole spreadsheet (ie ~1 Million rows). Is it possible if
it could jsut add rows to the range that has data??

Thanks very much.
Elaine.


On 30 Apr, 11:29, "NickHK" wrote:
Elaine,
Try this:

Private Sub CommandButton1_Click()
RowInsertion Range("A10"), 100, 10
End Sub

Private Sub RowInsertion(argStartCell As Range, RowsToJump As Long,
Optional
RowsToInset As Long = 1)
Dim i As Long

For i = argStartCell.Row To Rows.Count Step RowsToJump
Rows(i & ":" & i + RowsToInset - 1).Insert Shift:=xlDown
'Just to see where rows added
Rows(i & ":" & i + RowsToInset - 1).Interior.ColorIndex = 10
Next

End Function

NickHK

"elaine" wrote in message

oups.com...



Thank you guys, they work perfectly. Just wondering is there a way I
can insert X rows every Y rows?


Thanks for your help :)


elaine.- Hide quoted text -


- Show quoted text -





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
Cannot insert worksheet in exel - not available in insert menu pedro39 Excel Worksheet Functions 1 July 24th 08 12:09 PM
insert row / insert column command buttons fairgreen Excel Worksheet Functions 1 October 29th 07 02:41 PM
Macro to insert copy and insert formulas only to next blank row bob Excel Programming 0 June 30th 06 12:02 PM
Can I auto insert a worksheet when I insert a value in a cell. iainc Excel Worksheet Functions 0 April 27th 06 08:37 AM
Insert cell/format/text/fontsize and auto insert into header? Unfurltheflag Excel Programming 2 November 3rd 04 05:39 PM


All times are GMT +1. The time now is 04:48 AM.

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"