2013-02-05 51 views
0

如何使用excel或任何其他更簡單的語言實現此目的?使用excel分割字符串(101500810100015835001000)基於字符

original data: 
100301010100019743024000 

after formatting: 
100,3010,1,01,000,1974,3024,000 

Segment 1 = 3 char 
Segment 2 = 4 char 
Segment 3 = 1 char 
Segment 4 = 2 char 
Segment 5 = 3 char 
Segment 6 = 4 char 
Segment 7 = 4 char 
Segment 8 = 3 char 

非常感謝。

回答

0

VBA具有left(),right()mid()功能爲exactly this purpose

做到這一點會看起來像一個函數:

MsgBox (FmtStr("100301010100019743024000")) 

爲您提供了這樣一個對話框:

enter image description here

如果

Function FmtStr (MyStr As String) As String 
    If Len (MyStr) <> 24 Then 
     FmtStr = "?" 
    Else 
     FmtStr = _ 
      Mid (MyStr, 1, 3) + "," + _ 
      Mid (MyStr, 4, 4) + "," + _ 
      Mid (MyStr, 8, 1) + "," + _ 
      Mid (MyStr, 9, 2) + "," + _ 
      Mid (MyStr, 11, 3) + "," + _ 
      Mid (MyStr, 14, 4) + "," + _ 
      Mid (MyStr, 18, 4) + "," + _ 
      Mid (MyStr, 22, 3) 
    End If 
End Function 

與調用此只需要在Excel公式中使用:

=concatenate(mid(a1,1,3), ",", mid(a1,4,4), ",", ... ",", mid(a1,22,3)) 

(假設原始字符串當然是在A1單元格中)。

+0

非常感謝您爲此付出的努力!但我很遺憾地說,這只是我第一次接觸VBA,而且我迷失在使用它。如何開始非常基本的步驟?我很抱歉。 – Yeo

+0

@Yeo,就像學習大多數東西一樣,關於這個主題的好書很方便。我總是發現傻瓜指南不好,或者你可以看看http://superuser.com/questions/160455/good-books-for-learning-excel-vba – paxdiablo

+0

非常感謝你。 Excel的公式非常簡單!謝謝! – Yeo