Split data

Deepk

Board Regular
Joined
Mar 21, 2018
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I want a macro for changing the following data

Input:
AB2345
SD7890
AB
XC
CB2345
GH6543
SD
FG
ER2345
CV3455
GH
MN
WX9876
RE3456
HJ
KL

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

Output:

AB2345AB
SD7890XC
CB2345SD
GH6543FG
ER2345GH
CV3455MN
WX9876HJ
RE3456KL

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

Thanks in advance.
 
Last edited:
You are probably going to use Peter's new code in Message #20 , but, for the record, here is my code modified to handle your new data structure. Note that I have assumed the gaps you show between the groups of values is to delineate one cell's values from another and does not represent a blank cell on the worksheet between them.
Code:
Sub Split_Data()
  Dim LastRow As Long, ArrA As Variant, ArrB As Variant
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  ArrA = Application.Transpose(Split(Join(Application.Transpose(Range("A1:A" & LastRow)), vbLf), vbLf))
  ArrB = Application.Transpose(Split(Join(Application.Transpose(Range("B1:B" & LastRow)), vbLf), vbLf))
  Range("C1").Resize(UBound(ArrA)) = ArrA
  Range("D1").Resize(UBound(ArrB)) = ArrB
End Sub
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You are probably going to use Peter's new code in Message #20 , but, for the record, here is my code modified to handle your new data structure. Note that I have assumed the gaps you show between the groups of values is to delineate one cell's values from another and does not represent a blank cell on the worksheet between them.

Thank you Rick and Peter. you people are are awesome.
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

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