0
yoink

Help with Excel

Recommended Posts

Hey all,

I've got a problem in Excel I was hoping someone here might know how to solve.

I have two columns:

|aaaa|1,2,3|
|bbbb|3,8,9|
|gggg|1,6,7|


What I need to do is break the second column up so that each number appears in a new row, like so:
(periods are just fillers for formatting on here)

|aaaa|1|
|.......|2|
|.......|3|
|bbbb|3|
|.......|8|
|.......|9|
|gggg|1|
|.......|6|
|.......|7|


I was looking to wirte a macro to do this automatically but can't figure out how to do it...

Any tips or help would be much appreciated!

Cheers

Share this post


Link to post
Share on other sites
Here ya go


Sub Yoink()

Dim a() As String
Dim i As Integer
i = 1

While Range("A" & i).Value <> ""

a = parseIt(i)

For j = 0 To UBound(a)
Range("B" & i + j).Value = a(j)
Range("A" & i + j + 1).Select
If j <> UBound(a) Then Selection.EntireRow.Insert
Next

i = i + j
Wend


End Sub


Public Function parseIt(iRowNumber As Integer) As String()
Dim k As Integer
Dim j As Integer
Dim s As String
Dim jeux() As String

s = Trim(Cells(iRowNumber, 2).Value)

'let's see if there are more than one set if not just return that
j = InStr(s, ",")

If j = 0 Then
ReDim jeux(0) As String
jeux(0) = s
parseIt = jeux
Exit Function
Else
'so there's at least 2
While j <> 0
ReDim Preserve jeux(k)

jeux(k) = Mid(s, 1, j - 1)
s = Right(s, (Len(s) - j))
j = InStr(s, ",")

k = k + 1
Wend

ReDim Preserve jeux(k)
jeux(k) = s
parseIt = jeux
End If

End Function

Share this post


Link to post
Share on other sites
Quote

That is VBA. You will need to access Tools Macro Visual basic editor.

Then create a module and cut-n-paste the code.



Are we talking MSOffice Professional? If so which edition? I run MSOffice Professional Edition 2000 currently, if you have that version, or even MSOffice 1997, PM me, i'd be glad to help. I can write the formula send it to you, then you just copy and paste in the appropriate cell.....done!
-Richard-
"You're Holding The Rope And I'm Taking The Fall"

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

0