PDA

View Full Version : VBA: search for multiple words



fh_swf
01-29-2020, 09:21 AM
Hello everyone!

I wrote a VBA program to search column A for the word "hello" in a table. As soon as the word is found in the column, the program transfers the row in the column to the right to a new table. This works fine. Now I want to search for several words at once. Unfortunately, this doesn't work ... Can someone look at the VBA code and tell me what I did wrong? Many thanks in advance!

The Code


Sub test()
T = "T1"
X = "A"
AX = 1

Z = "T4"
Y = 2
AY = "B"

Do Until Suche <> ""
Suche = ("hello"; "my"; "another")

Loop
Set A = Worksheets(T)
Set B = Worksheets(Z)
Y = Y

With A.Columns(X)
Set Gefunden = .Find(Suche, LookIn:=xlValues)
If Not Gefunden Is Nothing Then
Erste = Gefunden.Address
Do 'für alle Fundstellen
B.Cells(Y, AY).Resize(1, AX) = Gefunden.Offset(0, 1).Resize(1, AX).Value
Y = Y + 1
Set Gefunden = .FindNext(Gefunden)
Loop Until Gefunden.Address = Erste
End If
End With
End Sub

snb
01-29-2020, 09:34 AM
Mehrmals suchen=Filtern


Sub M_snb()
with sheet1.columns(1)
for each it in array("hello","my","another")
.autofilter 1,it
c00=c00 & vblf & it & ": " & .specialcells(12).count-1
.autofilter
next
end with

msgbox c00
End Sub

fh_swf
01-29-2020, 10:09 AM
Mehrmals suchen=Filtern


Sub M_snb()
with sheet1.columns(1)
for each it in array("hello","my","another")
.autofilter 1,it
c00=c00 & vblf & it & ": " & .specialcells(12).count-1
.autofilter
next
end with

msgbox c00
End Sub

Hier kriege ich die Fehlermeldung: Objekt erforderlich

snb
01-29-2020, 10:18 AM
Please don't quote !

ersetze Sheet1 von Tabelle1 (oder ähnliches).