Macro for searching multiple criteria in a cell
Solved
mickysor
-
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
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
-
Good evening,
You don’t specify whether you want references or a filter...
A proposal for a dynamic filter:
Filter multiple.xls
eric -
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 -
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 -
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. -
> 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 -
-
-
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.