Macro for searching multiple criteria in a cell

Solved
mickysor -  
 mickysor -
Hello,

In column A:A I would like to create a search macro. The problem is that I would like to be able to perform a multi-criteria search. for example in cell A3 there is "italie rome 133". I would like to be able to search for "italie 133" for example.

Thank you for your help

8 answers

  1. eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281
     
    Good evening,

    You don’t specify whether you want references or a filter...
    A proposal for a dynamic filter:
    Filter multiple.xls

    eric
    3
    1. mickysor
       
      Hello,
      How did you make this dynamic filter, it’s exactly what I wanted!!!
      0
    2. eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281
       
      Hello,

      In VBA, right-click on the sheet tab name and 'View Code...'
      eric
      0
  2. melanie1324
     
    Hello,

    I’m not sure if this is exactly what you want but here’s a lead:

    one tip: press F8 (it triggers code line by line) and move your mouse without clicking on a cell to understand what it does

    Sub x()

    text = InputBox("Merci d'indiquer le texte recherché :", "texte recherché") 'allows the user to enter what you’re looking for
    If text <> "" Then 'if you didn’t enter anything, the macro stops
    i = 2 'starts at row 2
    Do While Cells(i, 1) <> "" 'the loop runs until there is nothing in a cell of column A
    nbtexte = Len(text) 'nbtexte = number of characters of the searched text
    cellule = Cells(i, 1) 'cellule is equal to the value in your cell
    Do While Len(cellule) > 0
    If UCase(Left(cellule, nbtexte)) = UCase(text) Then
    'put here what should happen when you find your text
    cellule = "a"
    End If
    cellule = Right(cellule, Len(cellule) - 1)
    Loop
    i = i + 1
    Loop
    End If

    End Sub
    0
  3. ccm81 Posted messages 11033 Status Member 2 434
     
    hello

    perhaps something like this

    For li = 21 To 24 a = InStr(1, Cells(li, 1), "Italie") b = InStr(1, Cells(li, 1), "133") If a * b > 0 Then MsgBox ("trouvé" & " - " & li) End If Next li


    Rq. pay attention to case, otherwise Ucase will convert to uppercase

    have a good continuation
    0
  4. melanie1324
     
    Hello,

    but the ucase function allows transforming to uppercase, so that it allows comparing two identical texts and no accent issues.

    besides, your code only allows searching for Italie 133 while mine, you can search any text.
    0
  5. ccm81 Posted messages 11033 Status Member 2 434
     
    > melanie

    you are absolutely right, i wanted to suggest an idea to simply respond to the question asked
    but
    the text searched for is a part of the cell content, so instruction(s) apply.

    have a good day
    0
  6. mickysor
     
    Good evening, sorry Mélanie, your macro doesn’t work in Excel 2003
    0
  7. mickysor
     
    is it possible to do this type of search with a formula?
    0
  8. Mike-31 Posted messages 18405 Registration date   Status Contributor Last intervention   5 147
     
    Hi,

    in the cell you have this type of data, for example in A1 you have Italy Rome 133 !

    if yes, and if I understand correctly in column A you have several identical data Italy Rome 133 or are they different like Italy 133 !

    --
    A+
    Mike-31

    A period of failure is a perfect time to sow the seeds of knowledge.
    0
    1. ccm81 Posted messages 11033 Status Member 2 434
       
      Hello Mike-31

      this is what I understood, that's why I proposed to instruct in post 2

      good luck
      0
    2. mickysor
       
      Thank you, I’ll try.
      0
    3. mickysor
       
      I added the code but I think we need to create a specific search button.
      0
    4. mickysor
       
      I succeeded!! can you set it to resolved. I don’t know how to do it on these posts
      0