如何以某种方式分裂细胞?

时间:2019-09-17 13:10:26

标签: excel

我有一个包含有关主题数据的单元格列表。这些主题同时包含两种语言,我需要用相同的结构将这两种语言分开。该单元的结构如下:

turkishword1 = englishword1; turkishword2 = englishword2

我需要将单元格分成“;”部分在每个主题之间。

喜欢这个

COLUMN1
turkishword1 ; turkishword2

COLUMN2
englishword1 ; englishword2

you can easily see what I want in this picture;

我该如何实现?预先感谢。

4 个答案:

答案 0 :(得分:4)

如果您具有Office 365或更高版本,则可以将TEXTJOIN用作数组公式:

=TEXTJOIN(";",TRUE,TRIM(MID(SUBSTITUTE(SUBSTITUTE($A2,"=",";"),";",REPT(" ",999)),((ROW($ZZ$1:INDEX($ZZ:$ZZ,LEN($A2)-LEN(SUBSTITUTE($A2,";",""))+1))-1)*2+(COLUMN(A:A)-1))*999+1,999)))

作为数组公式,退出编辑模式时必须用Ctrl-Shift-Enter代替Enter进行确认。

在B2中输入并使用Ctrl-Shift-Enter后,上下复制。

enter image description here

答案 1 :(得分:3)

怎么样:

Sub parseIT()
    Dim i As Long, N As Long, p1 As String, p2 As String
    Dim arr1, arr2, a

    N = Cells(Rows.Count, "A").End(xlUp).Row


    For i = 2 To N
        p1 = ""
        p2 = ""
        arr1 = Split(Cells(i, 1).Text, ";")
        For Each a In arr1
            arr2 = Split(a, "=")
            p1 = p1 & ";" & arr2(0)
            p2 = p2 & ";" & arr2(1)
        Next a
        Cells(i, 2) = Mid(p1, 2)
        Cells(i, 3) = Mid(p2, 2)
    Next i
End Sub

here

这假定数据从 A 列的第2行开始。

答案 2 :(得分:1)

而且,如果您拥有Excel 2010+,则可以使用Power Query(又名Get&Transform

除了自定义列之外,大多数操作都可以通过用户界面完成

  • 添加索引列
  • 通过semicolon
  • 分隔列
  • 选择“索引”列,然后选择Unpivot other columns
  • 删除“属性”列
  • 通过equal sign
  • 分隔列
  • Trim值列(用于删除前导/尾随空格)
  • Group索引列中的行,其中Operation = All Rows
  • 添加自定义列
    • 新列名称:主题1
    • 公式:= Table.Column([Grouped],“ Value.1”)
  • 使用;作为自定义分隔符提取值
  • 添加自定义列
    • 新列名称:主题2
    • 公式:= Table.Column([Grouped],“ Value.2”)
  • 使用;作为自定义分隔符提取值
  • 删除IndexTable

如果您从原始表中添加/删除项目或行,则可以通过单击鼠标轻松地更新结果。

这是 M代码,您可以从Power Query界面将其粘贴到高级编辑器中:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"subjects", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Index", "subjects", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"subjects.1", "subjects.2", "subjects.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"subjects.1", type text}, {"subjects.2", type text}, {"subjects.3", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Index"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Removed Columns", "Value", Splitter.SplitTextByDelimiter("=", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Trimmed Text" = Table.TransformColumns(#"Split Column by Delimiter1",{{"Value.1", Text.Trim, type text}, {"Value.2", Text.Trim, type text}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Trimmed Text",{{"Value.1", type text}, {"Value.2", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type2", {"Index"}, {{"Grouped", each _, type table [Index=number, Value.1=text, Value.2=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Subject 1", each Table.Column([Grouped],"Value.1")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Subject 1", each Text.Combine(List.Transform(_, Text.From), " ; "), type text}),
    #"Added Custom1" = Table.AddColumn(#"Extracted Values", "Subject 2", each Table.Column([Grouped],"Value.2")),
    #"Extracted Values1" = Table.TransformColumns(#"Added Custom1", {"Subject 2", each Text.Combine(List.Transform(_, Text.From), " ; "), type text}),
    #"Removed Columns1" = Table.RemoveColumns(#"Extracted Values1",{"Index", "Grouped"})
in
    #"Removed Columns1"

enter image description here

答案 3 :(得分:0)

首先,对整个数组使用“文本到列”工具:

  • 数据->文本到列->定界->分号-> Destination = C3

假设每个单元格最多包含3个项目,那么您会在C:E列中看到分离的数据。

接下来,您使用TRIM函数:

  • F3 = TRIM(C3),向右下方复制

最后,将这两个功能用于subject1和subject2:

=LEFT(F3;FIND("=";F3)-1)&IF(LEN(G3)>0;"; "&LEFT(G3;FIND("=";G3)-1);"")&IF(LEN(H3)>0;"; "&LEFT(H3;FIND("=";H3)-1);"")
=RIGHT(F3;LEN(F3)-FIND("=";F3)-1)&IF(LEN(G3)>0;" ; "&RIGHT(G3;LEN(G3)-FIND("=";G3)-1);"")&IF(LEN(H3)>0;" ; "&RIGHT(H3;LEN(H3)-FIND("=";H3)-1);"")

同样,这是最多3个项目(但可能更少)。

这是这样的: https://i.imgur.com/KObTUej.jpg

(抱歉,无法发布没有声誉的图片)