Excel VBA MID()

Zyel

Board Regular
Joined
Jun 2, 2009
Messages
75
I've this long line of data

018:000000004000000297,004:W101,003:PAL,007:930.000,003:KAR,002:40,001:1,005:23.25,004:FERT,006:FM0001;018:000000004000000297,004:W101,002:MT,007:930.000
aaa:bbbbbbbbbbbbbbbbbb,aaa:bbbb,aaa:bbb,aaa:bbbbbbb

For the numbers in aaa, it is the length of data that is after the semi colon :))

I'm trying to write a code where it will gives me this result

000000004000000297 | W101 | PAL | 930.000 | KAR | 40 | 1 | 23.25

I've been trying to use MID and LOOP statement for whole day... but not quite able to get it to work
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Split() is probably more useful here:
Code:
Sub Resplice()
iStr = "018:000000004000000297,004:W101,003:PAL,007:930.000,003:KAR,002:40,001:1,005:23.25,004:FERT,006:FM0001;018:0000000040000 00297,004:W101,002:MT,007:930.000 aaa: bbbbbbbbbbbbbbbbbb , aaa: bbbb , aaa: bbb , aaa: bbbbbbb"
s = Split(iStr, ",")
oStr = ""
For x = 0 To 7
    o = Split(s(x), ":")
    oStr = oStr + " | " & o(1)
Next x
MsgBox oStr
End Sub

Maybe you want the data split across cells rather than in a variable.
Modify the code accordingly.
 
Upvote 0

Forum statistics

Threads
1,215,350
Messages
6,124,431
Members
449,158
Latest member
burk0007

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