Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Duplicating Rows

I have a set of 1000 rows. The first cell in each row contains 4,6,8,10,or 0.
I need to duplicate each row as many times as the number in the first column.

As validated by the results of the past hour, I don't have a clue how to start.

Please help

Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Duplicating Rows

Jim,

While not perfect, the following code is working for me.
Assumes Column A is the column with the numbers.
Please note that you will be using close to the maximum number
of rows in a spread sheet.

'------------------------------------------------------
Sub MakeBigList()
Dim lngNum As Long
Dim lngFirstValue As Long
Dim lngColumnsWide As Long
Dim rngNewRng As Excel.Range
Dim rngCell As Excel.Range
Dim rngList As Excel.Range

Application.ScreenUpdating = False
lngColumnsWide = ActiveSheet.UsedRange.Columns.Count
Set rngList = Range("A1", Cells(Rows.Count, 1).End(xlUp))

For lngNum = rngList.Count To 1 Step -1
Set rngCell = Cells(lngNum, 1)
lngFirstValue = Val(rngCell.Value)
If lngFirstValue 0 Then
Set rngNewRng = rngCell(2, 1).Resize(lngFirstValue, lngColumnsWide)
rngNewRng.Insert shift:=xlShiftDown
Range(rngCell(2, 1), Cells(lngNum + lngFirstValue, _
lngColumnsWide)).Value = rngCell.Resize(1, lngColumnsWide).Value
ActiveSheet.DisplayPageBreaks = False
End If
Next 'lngNum

Application.ScreenUpdating = True
Set rngNewRng = Nothing
Set rngCell = Nothing
Set rngList = Nothing
End Sub
'------------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Jim Berglund" wrote in message
news:ck8Yd.639045$6l.356794@pd7tw2no...
I have a set of 1000 rows. The first cell in each row contains 4,6,8,10,or 0.
I need to duplicate each row as many times as the number in the first column.
As validated by the results of the past hour, I don't have a clue how to start.
Please help
Jim
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Duplicating Rows

Well, I was right - I didn't have a clue as to how to start!

It works!

And there's a lot for me to think through.

Thanks, Jim

Jim Berglund


"Jim Cone" wrote in message
...
Jim,

While not perfect, the following code is working for me.
Assumes Column A is the column with the numbers.
Please note that you will be using close to the maximum number
of rows in a spread sheet.

'------------------------------------------------------
Sub MakeBigList()
Dim lngNum As Long
Dim lngFirstValue As Long
Dim lngColumnsWide As Long
Dim rngNewRng As Excel.Range
Dim rngCell As Excel.Range
Dim rngList As Excel.Range

Application.ScreenUpdating = False
lngColumnsWide = ActiveSheet.UsedRange.Columns.Count
Set rngList = Range("A1", Cells(Rows.Count, 1).End(xlUp))

For lngNum = rngList.Count To 1 Step -1
Set rngCell = Cells(lngNum, 1)
lngFirstValue = Val(rngCell.Value)
If lngFirstValue 0 Then
Set rngNewRng = rngCell(2, 1).Resize(lngFirstValue, lngColumnsWide)
rngNewRng.Insert shift:=xlShiftDown
Range(rngCell(2, 1), Cells(lngNum + lngFirstValue, _
lngColumnsWide)).Value = rngCell.Resize(1,
lngColumnsWide).Value
ActiveSheet.DisplayPageBreaks = False
End If
Next 'lngNum

Application.ScreenUpdating = True
Set rngNewRng = Nothing
Set rngCell = Nothing
Set rngList = Nothing
End Sub
'------------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Jim Berglund" wrote in message
news:ck8Yd.639045$6l.356794@pd7tw2no...
I have a set of 1000 rows. The first cell in each row contains
4,6,8,10,or 0.
I need to duplicate each row as many times as the number in the first
column.
As validated by the results of the past hour, I don't have a clue how to
start.
Please help
Jim



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
duplicating rows Patty Excel Discussion (Misc queries) 1 May 10th 10 07:26 PM
Formula for Duplicating Rows J4mesD4wson Excel Discussion (Misc queries) 3 April 1st 09 06:07 PM
Duplicating rows help needed ArthurN Excel Worksheet Functions 3 October 28th 07 09:41 PM
Formula for Duplicating Rows!! GOL Excel Discussion (Misc queries) 2 May 22nd 06 08:54 PM
Duplicating rows and changing cells sousas Excel Programming 1 January 21st 04 03:10 AM


All times are GMT +1. The time now is 06:59 PM.

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"