VBA or Code For split the data

Vishaal

Well-known Member
Joined
Mar 16, 2019
Messages
543
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. Web
Hi All,

Thanks in advance,

i have a data

[TABLE="width: 50"]
<tbody>[TR]
[TD]Coloumn 1[/TD]
[TD] Coloumn 2 [/TD]
[/TR]
[TR]
[TD]2305[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2054[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]0654[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

now i want to split, but when we split the data, "0" is not coming

[TABLE="width: 50"]
<tbody>[TR]
[TD]Col 1[/TD]
[TD]Col 2[/TD]
[TD]Col 3[/TD]
[TD]Col 4[/TD]
[TD]Col 5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2305[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD][/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2054[/TD]
[TD]2[/TD]
[TD][/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]0654[/TD]
[TD][/TD]
[TD]6[/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

pls provide the VBA code/ formula
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Given first cell (2305) is in A2 try this in B2 and copy across:

IF(VALUE(MID($A2,COLUMNS($B$1:B1),1))=0,"",MID($A2,COLUMNS($B$1:B1),1))
 
Upvote 0
How about

Book1
ABCDEF
1
21230512305
320542054
406540654
Data
Cell Formulas
RangeFormula
B2=MID($A2,COLUMNS($B$1:B1),1)
 
Upvote 0
And what about
Code:
Sub test()
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 To lr
        For j = 1 To Len(Cells(i, 1))
             Cells(i, j).Offset(0, 1) = Mid(Cells(i, 1), j, 1)
        Next
    Next
End Sub
 
Upvote 0
given first cell (2305) is in a2 try this in b2 and copy across:

If(value(mid($a2,columns($b$1:b1),1))=0,"",mid($a2,columns($b$1:b1),1))

Rich (BB code):
if(value(mid($a2,columns($b$1:b1),1))=0,"0",text(mid($a2,columns($b$1:b1),1)))
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,714
Members
452,995
Latest member
isldboy

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