【问题标题】:How To exclude a specific list of number at a specific position如何排除特定位置的特定数字列表
【发布时间】:2018-02-25 17:09:36
【问题描述】:

我有一个数字列表,我想删除与我想要保留的数字不同的每个数字,例如列表:

01 54 88  <== remove
09 52 55  <== remove 
08 55 67
00 66 22  <== remove
04 44 11  <== remove
04 52 74  <== remove
02 98 65  <== remove
05 55 33

所以我在这里删除了位置 4 处除“55”之外的每个数字 所以我保留:

08 55 67
05 55 33

这两个数字

用 Excel 可以做到吗?

注意:如果需要,我有一个 KuTools for Excel。

提前感谢您的帮助,对不起我的英语:)

【问题讨论】:

  • 删除号码的标准是什么?
  • 标准是如果数字“55”在第 4 位,如下例所示,它们是删除注释:我犯了一个错误,我很抱歉,现在更好了
  • 这在工作表中是什么样子的?你能在工作表中显示一些数据吗?例如。是 01 一列还是 01 54 88 一列?你把空格算作一个位置吗?
  • 01 54 88 是一栏 抱歉,这里是示例:i.imgur.com/CHJXTsN.png

标签: excel numbers position


【解决方案1】:

你可以使用一个简单的过滤器

text equals:  ???55???

之前

之后

【讨论】:

  • @pnuts 是的。也可以选择然后复制可见行;或使用高级过滤器并过滤到另一个位置。
  • 是的,谢谢,它看起来很棒,但是是否可以添加更多过滤器,例如“等于”???55???和???56???和???57???我的意思是超过 2 个
  • @Exceler 您可以为此使用高级过滤器。查看 HELP 以获得一般建议,特别是使用 Multiple criteria, one column, any criteria truewild card criteria 高级过滤器的优势在于您可以将其设置为将结果放置在其他位置。
  • @Exceler 在概念化您的多个过滤器时,您应该将它们与OR 连接起来。否则它将始终评估为FALSE
【解决方案2】:

试试这个:

Public Sub Keep55Rows()

Dim wb As Workbook
Set wb = ThisWorkbook

Dim ws As Worksheet

Set ws = wb.Worksheets("Sheet1")

Dim targetArray()
Dim targetRange As Range

Set targetRange = ws.Range("A1").CurrentRegion

targetArray = targetRange.Value2

Dim outputArray
ReDim outputArray(1 To UBound(targetArray, 1), 1 To UBound(targetArray, 2))

Dim rowCount As Long
Dim currentRow  As Long
Dim currentColumn As Long

For currentRow = LBound(targetArray, 1) To UBound(targetArray, 1)

    If InStr(1, CStr(targetArray(currentRow, 1)), "55") = 4 Then

        rowCount = rowCount + 1

        outputArray(rowCount, 1) = targetArray(currentRow, 1)

    End If

Next currentRow

outputArray = Application.WorksheetFunction.Transpose(outputArray)

ReDim Preserve outputArray(1 To rowCount)

outputArray = Application.WorksheetFunction.Transpose(outputArray)

With targetRange
    .Offset(.Rows.Count + 2, 0).Resize(UBound(outputArray, 1), UBound(outputArray, 2)) = outputArray
End With

End Sub

假定命名工作表中单元格 A1 的连续范围,但易于调整到感兴趣的范围。只需修改targetRangews 变量即可。

【讨论】:

    猜你喜欢
    • 2018-05-24
    • 2022-12-08
    • 2011-04-29
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多