Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
tom tom is offline
external usenet poster
 
Posts: 570
Default Break one line item into many...

Is there a way or a script I can run to break out one line item into many?
For example

A B (columns)
2 A5285
3 A2358

I would like Excel to recognize that I want 2 lines created from colunm A
and fill A5285 into column B next to it. And subsequently I would like it to
recognize 3 and create three lines from it etc..etc.. So it would look as
below

A B
2 A5285
2 A5285
3 A2358
3 A2358
3 A2358

Thanks in advance!!

Tom



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Break one line item into many...

I'm not the best VBA programmer but this seems to work ok on my end.

Sub buildlist()
Dim rng As Range
Dim cell As Range, rw As Long
Dim sh As Worksheet, i As Long
Set sh = Worksheets("Sheet2")
With Worksheets("Sheet1")
Set rng = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With
rw = 2
sh.Range("A2:B65536").ClearContents
For Each cell In rng
For i = 1 To cell.Offset(0, 0).Value
sh.Cells(rw, 1).Value = cell.Value
sh.Cells(rw, 2).Value = cell.Offset(0, 1).Value
rw = rw + 1
Next i
Next cell
End Sub

Assumptions:

Data is on Sheet1 in the range A2:Bn and is a contiguous block (the macro
stops "looking" for data when it encounters an empty cell in column A)
The list will be output to Sheet2 starting in cell A2. So, you need to make
sure Sheet2 exists!
Each time the macro is run it will delete the previous list.

Try this on a COPY of your file first!

--
Biff
Microsoft Excel MVP


"Tom" wrote in message
...
Is there a way or a script I can run to break out one line item into many?
For example

A B (columns)
2 A5285
3 A2358

I would like Excel to recognize that I want 2 lines created from colunm A
and fill A5285 into column B next to it. And subsequently I would like it
to
recognize 3 and create three lines from it etc..etc.. So it would look as
below

A B
2 A5285
2 A5285
3 A2358
3 A2358
3 A2358

Thanks in advance!!

Tom





  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,836
Default Break one line item into many...

Someone at this DG gave me this macro back in January (or somewhere around
that time). Hope it works for you...


Sub InsertAnyRows()

Dim insertNumber As Range
Dim insertStart As Range
Dim redRng As Range
Dim i As Integer

Set insertNumber = Application.InputBox _
(Prompt:="Select a point to begin inserting rows. For instance, choose first
non blank cell in Column A", Title:="Add a row", Type:=8)
insertNumber.Select
If insertNumber <= 0 Then
MsgBox ("Invalid Number Entered")
Exit Sub
End If
Dim MyRow As Long

lastcell = Cells(Rows.Count, "A").End(xlUp).Row
MyRow = 1
Do Until MyRow = lastcell
For i = 1 To Cells(MyRow, 1)

If Cells(MyRow, 1) < "" Then
Cells(MyRow + 1, 1).Select
Selection.EntireRow.Insert shift:=xlDown
End If

Next
lastcell = Cells(Rows.Count, "A").End(xlUp).Row
MyRow = MyRow + 1
Loop

End Sub


All you have to do is split the data so that the number shows in Column A
and you can do this by the following method: Data Text to Columns.

Hope it works for you.

Ryan--




"Tom" wrote:

Is there a way or a script I can run to break out one line item into many?
For example

A B (columns)
2 A5285
3 A2358

I would like Excel to recognize that I want 2 lines created from colunm A
and fill A5285 into column B next to it. And subsequently I would like it to
recognize 3 and create three lines from it etc..etc.. So it would look as
below

A B
2 A5285
2 A5285
3 A2358
3 A2358
3 A2358

Thanks in advance!!

Tom



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
Automating a line item for several worksheets? tpmax Excel Worksheet Functions 1 June 26th 07 03:56 AM
Break cell into multiple lines by line break Chia Excel Discussion (Misc queries) 1 August 20th 06 06:37 AM
Line Break Ramthebuffs Excel Discussion (Misc queries) 4 August 22nd 05 08:52 PM
Trend Line - break bob Excel Worksheet Functions 1 June 29th 05 09:24 PM
line break in a cell luvgreen Excel Worksheet Functions 2 June 14th 05 06:48 PM


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