Consulting

Results 1 to 4 of 4

Thread: VBA: search for multiple words

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    2
    Location

    VBA: search for multiple words

    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
    Last edited by Paul_Hossler; 01-29-2020 at 09:42 AM. Reason: Added CODE tags and un-Bolded it

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    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

  3. #3
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    2
    Location
    Quote Originally Posted by snb View Post
    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

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Please don't quote !

    ersetze Sheet1 von Tabelle1 (oder ähnliches).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •