Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default I need some help with Arrays

I'm trying to get the data from this format:
MNO Sort ZONES IN SORT PROGRAM
23 80011 80011, 80042
47 80012 80012, 80041
53 80013 80013
33 80014 80014, 80044

To this Format:
MNO Sort ZONES IN SORT PROGRAM
23 80011 80011
23 80011 80042
47 80012 80012
47 80012 80041
53 80013 80013
33 80014 80014
33 80014 80044

So that each of the comma delimeted items in the last column is split out to
it's own row, with the MNO and the Sort listed for each of the split items.

Any ideas?

Thanks
Mike

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default I need some help with Arrays

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim ary As Variant
Dim NumRows As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = LastRow To 2 Step -1

ary = Split(.Cells(i, "C"), ",")
If UBound(ary) LBound(ary) Then

NumRows = UBound(ary) - LBound(ary)
.Rows(i + 1).Resize(NumRows).Insert
.Cells(i + 1, "A").Resize(NumRows) = Cells(i, "A").Value
.Cells(i + 1, "B").Resize(NumRows) = Cells(i, "B").Value
.Cells(i, "C").Resize(NumRows + 1) =
Application.transpose(ary)
End If
Next i

End With

End Sub

--
__________________________________
HTH

Bob

"mikebres" wrote in message
...
I'm trying to get the data from this format:
MNO Sort ZONES IN SORT PROGRAM
23 80011 80011, 80042
47 80012 80012, 80041
53 80013 80013
33 80014 80014, 80044

To this Format:
MNO Sort ZONES IN SORT PROGRAM
23 80011 80011
23 80011 80042
47 80012 80012
47 80012 80041
53 80013 80013
33 80014 80014
33 80014 80044

So that each of the comma delimeted items in the last column is split out
to
it's own row, with the MNO and the Sort listed for each of the split
items.

Any ideas?

Thanks
Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default I need some help with Arrays

Thank you. I went a slightly different direction, but you gave me the nudge
I needed.

Sub SplitList2()
Dim strArray() As Variant, strItem() As String
Dim SelCnt As Long

ReDim strArray(SelCnt)

strArray = Selection.value

SelCnt = UBound(strArray, 1)
If SelCnt < 1 Then GoTo SL2_End

ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.count)
Range("$A$1").Activate

'Assume the first row is labels and print them
For i = 1 To UBound(strArray, 2)
ActiveCell.Offset(0, i - 1).value = strArray(1, i)
Next i

ActiveCell.Offset(1, 0).Activate

For i = 2 To SelCnt
strItem = Split(strArray(i, 3), ",")
'Because Split uses a zero based array I needed to add 1 to the count
NumRows = UBound(strItem) + 1
ActiveCell.Resize(NumRows) = strArray(i, 1)
ActiveCell.Offset(0, 1).Resize(NumRows) = strArray(i, 2)
ActiveCell.Offset(0, 2).Resize(NumRows) = Application.Transpose(strItem)
ActiveCell.Offset(NumRows, 0).Activate
Next i

SL2_End:

End Sub


Mike

"Bob Phillips" wrote:

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim ary As Variant
Dim NumRows As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = LastRow To 2 Step -1

ary = Split(.Cells(i, "C"), ",")
If UBound(ary) LBound(ary) Then

NumRows = UBound(ary) - LBound(ary)
.Rows(i + 1).Resize(NumRows).Insert
.Cells(i + 1, "A").Resize(NumRows) = Cells(i, "A").Value
.Cells(i + 1, "B").Resize(NumRows) = Cells(i, "B").Value
.Cells(i, "C").Resize(NumRows + 1) =
Application.transpose(ary)
End If
Next i

End With

End Sub

--
__________________________________
HTH

Bob

"mikebres" wrote in message
...
I'm trying to get the data from this format:
MNO Sort ZONES IN SORT PROGRAM
23 80011 80011, 80042
47 80012 80012, 80041
53 80013 80013
33 80014 80014, 80044

To this Format:
MNO Sort ZONES IN SORT PROGRAM
23 80011 80011
23 80011 80042
47 80012 80012
47 80012 80041
53 80013 80013
33 80014 80014
33 80014 80044

So that each of the comma delimeted items in the last column is split out
to
it's own row, with the MNO and the Sort listed for each of the split
items.

Any ideas?

Thanks
Mike




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
Trouble with arrays (transferring values between two arrays) Keith R[_2_] Excel Programming 4 November 14th 07 12:00 AM
Working with ranges in arrays... or an introduction to arrays Glen Excel Programming 5 September 10th 06 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM
Arrays Colin Macleod Excel Programming 1 December 1st 03 04:32 PM
Arrays Torbjörn Steijer Excel Programming 2 November 13th 03 09:52 AM


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