例如,只要单元格不包含特定的文本子字符串,我就想从值列表中复制特定的值;
A B texta texta textd textd text1 texta text1.2 textb text1.3 textc text1.2 text2 texta would become: textb textb text2.1 textc text1.3 text1.2 text2 textb text2.1
是否有一个论坛可以复制一个单元格,只要它不包含特定的文本字符串和空白值?
谢谢!
答案 0 :(得分:1)
如果您的值在A列中,而被排除的两个值在C列中,那么在B列中,您可以放置此数组公式,然后按Ctrl + Shift + Enter。
= IFERROR(INDEX($ A $ 1:$ A $ 14,SMALL(IF(ISNUMBER(MATCH($ A $ 1:$ A $ 14,$ C $ 1:$ C $ 3,0)),“”, ROW($ A $ 1:$ A $ 14)-MIN(ROW($ A $ 1:$ A $ 14))+ 1),ROW(A1))),“”)
答案 1 :(得分:0)
您可以使用Instr
测试字符串是否存在。在ArrayList
中保留合格结果(如果不存在),并在末尾列出该列表:
Option Explicit
Public Sub GetValuesWithoutSubString()
Dim arr(), i As Long, list As Object
Const TEST_STRING As String = "text1"
With Worksheets("Sheet1")
arr = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
Set list = CreateObject("System.Collections.ArrayList")
For i = LBound(arr, 1) To UBound(arr, 1)
With list
If Not InStr(arr(i, 1), TEST_STRING) > 0 and arr(i, 1) <> vbNullString Then
.Add arr(i, 1)
End If
End With
Next i
.Range("B1").Resize(list.Count, 1) = Application.WorksheetFunction.Transpose(list.ToArray)
End With
End Sub
多个排除项:
Option Explicit
Public Sub GetValuesWithoutSubString()
Dim arr(), i As Long, list As Object
Dim exclusions(), found As Boolean, j As Long
exclusions = Array("text1", "texta")
'text1" and "texta
With Worksheets("Sheet1")
arr = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
Set list = CreateObject("System.Collections.ArrayList")
For i = LBound(arr, 1) To UBound(arr, 1)
found = False
With list
For j = LBound(exclusions) To UBound(exclusions)
If InStr(arr(i, 1), exclusions(j)) > 0 Then
found = True
Exit For
End If
Next
If Not found Then .Add arr(i, 1)
End With
Next i
.Range("B1").Resize(list.Count, 1) = Application.WorksheetFunction.Transpose(list.ToArray)
End With
End Sub