excel 如何拆分特定列名称下的列值

qcbq4gxm  于 2023-05-01  发布在  其他
关注(0)|答案(4)|浏览(138)

我有如下表所示的主要价值。现在,我需要将each值保留在特定的列名下。所有值都以空格分隔。例如,主值为:2 3 6 7。
现在,2应该位于列名2下。3应该在列名3下,6应该在列名6下,7应该在列名7下。在Excel中有一个选项名为“文本到列”。使用这个函数,值可以拆分,但它不会转到它的特定列名。

请帮帮忙,我该怎么做。先谢谢你了。[我正在使用“Microsoft Office Professional Plus 2019”]

8hhllhi2

8hhllhi21#

如果你不使用MS365,你可以这样做:

·单元格B3中使用的公式

=LET(x,FILTERXML("<m><b>"&SUBSTITUTE($A3," ","</b><b>")&"</b></m>","//b"),
IFERROR(INDEX(x,MATCH(1,N(x=B$1),0)),""))

右填充和向下填充!
使用MS365函数--〉TEXTSPLIT()

·单元格B3中使用的公式

=LET(x,TEXTSPLIT($A3,," "),
IFERROR(INDEX(x,BYCOL($B$1:$K$1,LAMBDA(m,XMATCH(1,N(x+0=m))))),""))

和填写下来,没有必要填补的权利,因为它溢出。
由于您使用的是Microsoft Office Professional Plus 2019,您需要在退出编辑模式时按CTRL+SHIFT+ENTER。

·单元格B3中使用的公式

=IFERROR(INDEX(FILTERXML("<m><b>"&SUBSTITUTE($A3," ","</b><b>")&"</b></m>","//b"),
MATCH(1,N(FILTERXML("<m><b>"&SUBSTITUTE($A3," ","</b><b>")&"</b></m>","//b")=B$1),0)),"")

还可以为FILTERXML()公式定义名称

·单元格B3中使用的公式

=IFERROR(INDEX(MAIN_VALUE,MATCH(1,N(MAIN_VALUE=B$1),0)),"")

其中MAIN_VALUE

=FILTERXML("<m><b>"&SUBSTITUTE($A9," ","</b><b>")&"</b></m>","//b")

输入公式并退出编辑模式后,需要按CTRL+SHIFT+ENTER键。

编辑:发现公式适用于OP

·单元格B3中使用的公式

=IFERROR(LOOKUP(2,1/SEARCH(" "&B$1&" "," "&$A3&" "),B$1),"")

向下填充和向右填充!

uwopmtnx

uwopmtnx2#

数据拆分分组(VBA)

Sub SplitData()
    
    ' Define constants.
    Const DELIMITER As String = " "
    
    ' Reference the worksheet.
    Dim ws As Worksheet: Set ws = ActiveSheet ' improve!
    
    ' Reference the range.
    Dim rg As Range: Set rg = ws.UsedRange
    
    ' Write the row labels to an array.
    Dim rCount As Long: rCount = rg.Rows.Count - 1
    Dim rrg As Range: Set rrg = rg.Columns(1).Resize(rCount).Offset(1)
    Dim rData(): rData = rrg.Value
    
    ' Write the column labels to an array.
    Dim cCount As Long: cCount = rg.Columns.Count - 1
    Dim crg As Range: Set crg = rg.Rows(1).Resize(, cCount).Offset(, 1)
    Dim cData(): cData = crg.Value
    
    ' Convert the column labels to strings.
    Dim c As Long
    For c = 1 To cCount
        cData(1, c) = CStr(cData(1, c))
    Next c
    
    ' Reference the values range.
    Dim vrg As Range: Set vrg = rrg.Offset(, 1).Resize(, cCount)
    ' Define the values array.
    Dim vData(): ReDim vData(1 To rCount, 1 To cCount)
    
    ' Declare For...Next loop variables.
    Dim cIndexes, cIndex, SubStrings() As String, r As Long, rStr As String
    
    ' Loop through the row labels.
    For r = 1 To rCount
        rStr = CStr(rData(r, 1))
        If Len(rStr) > 0 Then
            ' Split the current row label into an array.
            SubStrings = Split(rStr, DELIMITER)
            ' Return the matching column indexes in an array.
            cIndexes = Application.Match(SubStrings, cData, 0)
            ' Write the matching values to the values array.
            For Each cIndex In cIndexes
                'Debug.Print cIndex
                If IsNumeric(cIndex) Then
                    vData(r, cIndex) = cData(1, cIndex)
                End If
            Next cIndex
        End If
    Next r

    ' Write the values array to the values range.
    vrg.Value = vData

End Sub

编辑

  • 添加了rStr,i.例如If Len(rStr) > 0 Then,以说明当行标签(列A中的值)为空时发生的类型不匹配错误。
g2ieeal7

g2ieeal73#

备选方案:

=MAKEARRAY(
    ROWS(A3:A7),
    COLUMNS(B1:K1),
    LAMBDA(κ,λ,
        LET(ζ,0+TEXTSPLIT(INDEX(A3:A7,κ)," "),
            INDEX(XLOOKUP(B1:K1,ζ,ζ,""),λ)
        )
    )
)
hmae6n7t

hmae6n7t4#

就像这样:
IF(IFERROR(FIND(B$1,$A2,1),0),B$1,"”)

根据评论:
这适用于10,会让你知道如何处理11,12等
但是您的示例没有任何超过10的值,因此假定10是最高值。IF(AND(IFERROR(FIND(10,A2,1),0)〉0,$B1 =1),"",IF(IFERROR(FIND(B$1,$A2,1),0),B$1,””))

相关问题