2016-03-09 74 views
0

我有多個單元格,如拆分多個單元格到列

。 EX CEL A1

m2_10cm[0.10],m2_20cm[0.20],m2_5cm[0.05],m3[1.9] 

和單元格A2

m3_22[2.2],m3_19[1.9] 

霍夫我可以把它拆分到一列像

Column B 
    Cell 1 m2_10cm[0.10] 
    Cell 2 m2_20cm[0.20] 
    Cell 3 m2_5cm[0.05] 
    Cell 4 m3[1.9] 
    Cell 5 m3_22[2.2] 
    Cell 6 m3_19[1.9] 

我會apriciate任何幫助

+1

您是否嘗試了文本到列,然後複製 - >粘貼特殊 - >移調? –

+0

你甚至可以嘗試錄製自己的文本到列,看看它出現了什麼。 – Jeeped

+0

感謝您的快速響應,但在我的情況下,它不夠。我需要使用公式來完成它,因爲我將它整理到數據驗證列表中 – wiecman

回答

0

在Excel中使用VBA代碼:

注意:Google如何將一個命令按鈕在工作表上並將其粘貼爲代碼。

Option Explicit 

' note: vbNullString is the same as "" (empty string) 

Const START_ROW = 1 
Const SRC_COL = 1 ' column A 
Const DST_COL = 2 ' column B 

' this gets triggered when the button is pressed 
Private Sub CommandButton1_Click() 
    ' call the routine 
    Call Go 
End Sub 

Function Go() 
    ' assume the button is on the sheet to be processed 
    Dim ws As Excel.Worksheet 
    Set ws = Excel.ActiveSheet 

    Dim srcRow As Integer ' current row being processed 
    Dim dstRow As Integer ' current row to put result in 
    srcRow = START_ROW: dstRow = START_ROW 

    ' keep going while column 'A' is not blank 
    While ws.Cells(srcRow, SRC_COL) <> vbNullString 
     Call Split(ws, ws.Cells(srcRow, SRC_COL), dstRow) 
     srcRow = srcRow + 1 
    Wend 
End Function 

Sub Split(ws As Excel.Worksheet, srcStr As String, ByRef dstRow As Integer) 
    If (srcStr = vbNullString) Then 
     'remove comment if you want blanks at the end 
     ' ex. Apple,Banana, 
     '  will create 3 entries, notice the comma at the end 
     'ws.Cells(dstRow, DST_COL) = vbNullString 
     'dstRow = dstRow + 1 
     Exit Sub 
    endif 

    ' find "," 
    Dim pos As Integer 
    pos = InStr(1, srcStr, ",") 
    If (pos = 0) Then 
     ' no "," - put the whole string 
     ws.Cells(dstRow, DST_COL) = Trim(srcStr) 
     dstRow = dstRow + 1 
    Else 
     ' has "," - put the left part of the string 
     ' ex: apple,banana,carrot 
     '  put "apple" 
     '  continue processing "banana,carrot" 
     ws.Cells(dstRow, DST_COL) = Trim(Mid(srcStr, 1, pos - 1)) 
     ' move to next row and process the right of the string 
     dstRow = dstRow + 1 
     Call Split(ws, Mid(srcStr, pos + 1), dstRow) 
    End If 
End Sub 
0

這裏是一個解決方案,您需要隱藏所有其他列: 說你有A1中的值然後放入以下公式:

B1: =IF(ISERR(FIND(",";A1;1));A1;LEFT(A1;FIND(",";A1;1)-1)) 
C1: =IF(ISERR(FIND(",";A1;1));"";RIGHT(A1;LEN(A1)-FIND(",";A1;1))) 

B1將包含列表中的第一個值,C1將包含列表減去第一個值。現在,您可以複製這些公式D1和E1,他們現在看起來像

D1: =IF(ISERR(FIND(",";C1;1));C1;LEFT(C1;FIND(",";C1;1)-1)) 
E1: =IF(ISERR(FIND(",";C1;1));"";RIGHT(C1;LEN(C1)-FIND(",";C1;1))) 

現在繼續,因爲你需要複製這個公式,只要在右側。

一旦做到這一點,你可以隱藏包含縮短列表中的所有列,開始與C,然後E等

+0

你也可以用同樣的方法做到這一點,把公式放在A2和A3中,然後將它們複製到A4和A5等...... 然後隱藏第3,5,7行等。 –