Excel:过滤/删除一个单元格中的某些数字

时间:2017-03-15 15:48:22

标签: excel excel-formula

请帮忙,

我擅长2列中的数字,例如:

10   10
20   2010, 2011
30   30100, 30200,30500
40   40

我想要的结果如下:

1,2,3,4,5,6,7,8,9
10,11
100,200,500
1,2,3,4,5,6,7,8,9

因此,如果第1列和第2列之间的结果为0,则数字从1到9。

有办法吗?

2 个答案:

答案 0 :(得分:0)

以下是VBA方法:

Function AdHoc(x As Variant, y As Variant) As String
    Dim v As Variant
    Dim i As Long
    Dim s As String

    v = Split(y, ",")
    If Val(x) = Val(v(0)) Then
        s = "1,2,3,4,5,6,7,8,9"
    Else
        For i = 0 To UBound(v)
            v(i) = Mid(Trim(v(i)), 1 + Len(Trim(Str(x))))
        Next i
        s = Join(v, ",")
    End If
    AdHoc = s
End Function

如果将其输入标准代码模块,则AdHoc可以直接在工作表中使用:

enter image description here

在上文中,我只是在单元格=adhoc(A1,B1)中输入C1,然后向下复制。

答案 1 :(得分:0)

如果要从第二列中的值的任何部分删除第一列中的字符,请尝试:

=IF(A1=B1,"1,2,3,4,5,6,7,8,9",SUBSTITUTE(SUBSTITUTE(B1," ",""),A1,""))

如果您只想从列的开头部分删除一列值两个值,请尝试:

=IF(B1=C1,"1,2,3,4,5,6,7,8,9",MID(SUBSTITUTE(SUBSTITUTE(","&C1," ",""),"," &B1,","),2,99))

请注意,对于最终结果,我删除了您在示例中显示的空格。

使用第二个公式:

enter image description here