2016-03-09 75 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行等。 –