One cell string to convert mulitple cell

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
I have data like below

Sheet1

*A
1DEX/25/26/48/80
2REX/88/125/358/10
3MEX/25/10/2/3/4/108

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:280px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Want to convert like below

Sheet1


*A
1DEX/25
2DEX/26
3DEX/48
4DEX/80
5REX/88
6REX/125
7REX/358
8REX/10
9MEX/25
10MEX/10
11MEX/2
12MEX/3
13MEX/4
14MEX/108

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:280px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
See if this is any use.
Code:
Sub Convert_Data()
  Dim p As String
  Dim c As Range
  Dim b
  Dim nr As Long, rws As Long
  
  Const d As String = "/"
  
  Application.ScreenUpdating = False
  nr = 1
  For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
    b = Split(c.Value, d)
    p = b(0)
    rws = UBound(b)
    Cells(nr, "B").Resize(rws).Value = Application.Transpose(Split(p & d & Join(Filter(b, p, False), " " & p & d)))
    nr = nr + rws
  Next c
  Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thanks Peter For your Help Code Working Perfect just i need the result in same column is this possible ?
 
Upvote 0
kevatarvind,

Sample raw data:


Excel 2007
A
1DEX/25/26/48/80
2REX/88/125/358/10
3MEX/25/10/2/3/4/108
4
5
6
7
8
9
10
11
12
13
14
15
Sheet1


After the macro:


Excel 2007
A
1DEX/25
2DEX/26
3DEX/48
4DEX/80
5REX/88
6REX/125
7REX/358
8REX/10
9MEX/25
10MEX/10
11MEX/2
12MEX/3
13MEX/4
14MEX/108
15
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Option Explicit
Sub ReorgData()
' hiker95, 04/15/2013
' http://www.mrexcel.com/forum/excel-questions/697082-one-cell-string-convert-mulitple-cell.html
Dim r As Long, lr As Long, s, nr As Long, i As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
For r = lr To 1 Step -1
  If InStr(Cells(r, 1), "/") > 0 Then
    nr = r
    s = Split(Cells(r, 1), "/")
    Rows(r + 1).Resize(UBound(s) - 1).Insert
    For i = 1 To UBound(s)
      Cells(nr, 1) = s(0) & "/" & s(i)
      nr = nr + 1
    Next i
  End If
Next r
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData macro.
 
Upvote 0
Thanks Peter For your Help Code Working Perfect just i need the result in same column is this possible ?
Add the blue line of code
Rich (BB code):
  Next c
  Columns("A").Delete
  Application.ScreenUpdating = True

I'm not suggesting you use this one (though you could, with maybe a little more tidying) - it was just for fun and to keep RR happy. :)
Rich (BB code):
Sub Convert_Data_v2()
  Dim c As Range

  For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
    Cells(Rows.Count, "B").End(xlUp).Offset(1).Resize(UBound(Split(c.Value, "/"))).Value = _
      Application.Transpose(Split(Split(c.Value, "/")(0) & "/" & Join(Filter(Split(c.Value, "/"), Split(c.Value, "/")(0), False), " " & Split(c.Value, "/")(0) & "/")))
  Next c
End Sub
 
Upvote 0
Thanks Hiker95 its working perfect thanks A Ton Both Peter and Hiker your people Are Brilliant :)
 
Upvote 0
kevatarvind,

Thanks for the feedback.

You are very welcome. Glad we could help.

Come back anytime.
 
Upvote 0

Forum statistics

Threads
1,203,643
Messages
6,056,520
Members
444,871
Latest member
Vishal Gupta

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top