OVH Cloud OVH Cloud

Comparaison method for Range

13 réponses
Avatar
Mathew
Hello,

I would like to make a macro which permit to searches a text chain within
ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is the
same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew

10 réponses

1 2
Avatar
Daniel
Bonjour.
Essaie :
Sub test()
Dim c As Range
Range("A1:B3").Select
For Each c In Selection
Var = InStr(1, c.Value, "this_word")
If Var > 0 Then
MsgBox c.Address
End If
Next c
End Sub

" Mathew" a écrit dans le message de news:

Hello,

I would like to make a macro which permit to searches a text chain within
ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is the
same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew




Avatar
anonymousA
Hi,

You're on the french Excel Newsgroup.

However,for instance, with this program, you can search the word "toto" thru
2 sheets ("Feuil1" and "Feuil2")
In this example, the program will return all the cells's adresses that match
with the required word.
If you want a specific match, you've got to add the parameter
Lookat:=xlwhole in the instruction .Find(What:="toto") and turn in
.Find(What:="toto",lookat:=xlwhole)

For Each f In Sheets(Array("Feuil1", "Feuil2"))
With f.Cells
Set c = .Find(What:="toto")
If Not c Is Nothing Then
firstaddress = c.Address
MsgBox c.Address
Set c = .FindNext(c)
Do While c.Address <> firstaddress And Not c Is Nothing
MsgBox c.Address
Set c = .FindNext(c)
Loop
End If
End With

Regards


Hello,

I would like to make a macro which permit to searches a text chain within
ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is the
same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew





Avatar
Clément Marcotte
En plus que le que le Matthew en question C'est un Matthieu trop
colonisé pour écrire en français.


"anonymousA" a écrit dans le
message de news:
Hi,

You're on the french Excel Newsgroup.

However,for instance, with this program, you can search the word
"toto" thru

2 sheets ("Feuil1" and "Feuil2")
In this example, the program will return all the cells's adresses
that match

with the required word.
If you want a specific match, you've got to add the parameter
Lookat:=xlwhole in the instruction .Find(What:="toto") and turn in
.Find(What:="toto",lookat:=xlwhole)

For Each f In Sheets(Array("Feuil1", "Feuil2"))
With f.Cells
Set c = .Find(What:="toto")
If Not c Is Nothing Then
firstaddress = c.Address
MsgBox c.Address
Set c = .FindNext(c)
Do While c.Address <> firstaddress And Not c Is Nothing
MsgBox c.Address
Set c = .FindNext(c)
Loop
End If
End With

Regards


Hello,

I would like to make a macro which permit to searches a text chain
within


ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the
range is the


same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew







Avatar
Clément Marcotte
Écris donc en français, maudit colonisé.
Avatar
Jan De Messemaeker
Et tant qu'on y est, s'il vous plaît n'embêtes pas les gens de bonne volonté
dans une dixaine (!) de groupes différents

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
+32-495-300 620
"Clément Marcotte" schreef in bericht
news:
Écris donc en français, maudit colonisé.



Avatar
Mathew
Salut,

merci pour ta reponse hier sur le news group.
Comme tu a l'air de maitriser, j'aimerai te pose une autre question :

Dans mon tableau, j'ai des cases avec:
Hiroyuki.Ohama:(CI) CHANGE
Yukiko.Kojima:(CI) CHANGE
etc...

(Les espaces du debut y sont aussi)

Et je dois copier le nom des users (par ex :Yukiko.Kojima) dans une autre
case.
Pour automatiser le truc sur tout le fichier je sais le faire, mais je ne
vois
pas comment reussir a shope le nom des users qui sont tous differents.
On peut peut etre prendre le mot avant le point (.) le mot apres le point,
mais
je ne sais pas comment faire ca...

T'as pas une idee, ya au moins 15000 lignes je peux pas le faire a la main!!


Merci,
Matthieu


"Daniel" wrote in message
news:ud#
Bonjour.
Essaie :
Sub test()
Dim c As Range
Range("A1:B3").Select
For Each c In Selection
Var = InStr(1, c.Value, "this_word")
If Var > 0 Then
MsgBox c.Address
End If
Next c
End Sub

" Mathew" a $BqD(Brit dans le message de news:

Hello,

I would like to make a macro which permit to searches a text chain
within


ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is
the


same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew








Avatar
isabelle
bonjour Mathew,

copie cette fonction dans un module,

Function MotCentre(ByVal Chaine$, _
Optional SeparateurX$ = " ", Optional SeparateurY$ = " ")
Dim posX, posY, nbcarT, nbcarX, MotIntérieurDélimité_X
nbcarT = Len(Chaine)
nbcarX = Len(SeparateurX)
posX = Application.Search(SeparateurX, Chaine)
posY = Application.Search(SeparateurY, Chaine, posX)
MotIntérieurDélimité_X = Right(Chaine, nbcarT - posX - nbcarX + 1)
On Error GoTo fin
MotCentre = Left(MotIntérieurDélimité_X, posY - posX - nbcarX)
Exit Function
fin:
MotCentre = MotIntérieurDélimité_X
End Function

et en la combinant avec la fonction SUPPRESPACE, tu auras le résultat
attendu.
=SUPPRESPACE(MotCentre(A1;" ";":"))

isabelle

Salut,

merci pour ta reponse hier sur le news group.
Comme tu a l'air de maitriser, j'aimerai te pose une autre question :

Dans mon tableau, j'ai des cases avec:
Hiroyuki.Ohama:(CI) CHANGE
Yukiko.Kojima:(CI) CHANGE
etc...

(Les espaces du debut y sont aussi)

Et je dois copier le nom des users (par ex :Yukiko.Kojima) dans une autre
case.
Pour automatiser le truc sur tout le fichier je sais le faire, mais je ne
vois
pas comment reussir a shope le nom des users qui sont tous differents.
On peut peut etre prendre le mot avant le point (.) le mot apres le point,
mais
je ne sais pas comment faire ca...

T'as pas une idee, ya au moins 15000 lignes je peux pas le faire a la main!!


Merci,
Matthieu


"Daniel" wrote in message
news:ud#

Bonjour.
Essaie :
Sub test()
Dim c As Range
Range("A1:B3").Select
For Each c In Selection
Var = InStr(1, c.Value, "this_word")
If Var > 0 Then
MsgBox c.Address
End If
Next c
End Sub

" Mathew" a $BqD(Brit dans le message de news:


Hello,

I would like to make a macro which permit to searches a text chain



within

ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is



the

same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew












Avatar
Mathew
Isabelle,

Merci pour ton aide.
Mais je ne vois pas comment on utilise la fct
=SUPPRESPACE(MotCentre(A1;" ";":"))
J'ecris ca ou ?
(Et dans le module ou j'ai copie le code, je dois faire une sub () ou bien
?)

Desole, je suis vraiment nul!!!
Matthieu


"isabelle" wrote in message
news:
bonjour Mathew,

copie cette fonction dans un module,

Function MotCentre(ByVal Chaine$, _
Optional SeparateurX$ = " ", Optional SeparateurY$ = " ")
Dim posX, posY, nbcarT, nbcarX, MotIntérieurDélimité_X
nbcarT = Len(Chaine)
nbcarX = Len(SeparateurX)
posX = Application.Search(SeparateurX, Chaine)
posY = Application.Search(SeparateurY, Chaine, posX)
MotIntérieurDélimité_X = Right(Chaine, nbcarT - posX - nbcarX + 1)
On Error GoTo fin
MotCentre = Left(MotIntérieurDélimité_X, posY - posX - nbcarX)
Exit Function
fin:
MotCentre = MotIntérieurDélimité_X
End Function

et en la combinant avec la fonction SUPPRESPACE, tu auras le résultat
attendu.
=SUPPRESPACE(MotCentre(A1;" ";":"))

isabelle

Salut,

merci pour ta reponse hier sur le news group.
Comme tu a l'air de maitriser, j'aimerai te pose une autre question :

Dans mon tableau, j'ai des cases avec:
Hiroyuki.Ohama:(CI) CHANGE
Yukiko.Kojima:(CI) CHANGE
etc...

(Les espaces du debut y sont aussi)

Et je dois copier le nom des users (par ex :Yukiko.Kojima) dans une
autre


case.
Pour automatiser le truc sur tout le fichier je sais le faire, mais je
ne


vois
pas comment reussir a shope le nom des users qui sont tous differents.
On peut peut etre prendre le mot avant le point (.) le mot apres le
point,


mais
je ne sais pas comment faire ca...

T'as pas une idee, ya au moins 15000 lignes je peux pas le faire a la
main!!




Merci,
Matthieu


"Daniel" wrote in message
news:ud#

Bonjour.
Essaie :
Sub test()
Dim c As Range
Range("A1:B3").Select
For Each c In Selection
Var = InStr(1, c.Value, "this_word")
If Var > 0 Then
MsgBox c.Address
End If
Next c
End Sub

" Mathew" a $BqD(Brit dans le message de
news:





Hello,

I would like to make a macro which permit to searches a text chain



within

ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is



the

same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew














Avatar
Daniel
Bonjour.
Tu peux essayer le code suivant :

Sub test()
Dim c As Range, Var As String, Pos As Integer
Range("A1:B3").Select
For Each c In Selection
Var = Trim(c.Value)
Pos = InStr(1, Var, ":")
If Var <> "" Then
If Pos > 0 Then
Var = Left(Var, Pos - 1)
End If
c.Value = Var
End If
Next c
End Sub

Cordialement.
Daniel
" Mathew" a écrit dans le message de news:

Salut,

merci pour ta reponse hier sur le news group.
Comme tu a l'air de maitriser, j'aimerai te pose une autre question :

Dans mon tableau, j'ai des cases avec:
Hiroyuki.Ohama:(CI) CHANGE
Yukiko.Kojima:(CI) CHANGE
etc...

(Les espaces du debut y sont aussi)

Et je dois copier le nom des users (par ex :Yukiko.Kojima) dans une autre
case.
Pour automatiser le truc sur tout le fichier je sais le faire, mais je ne
vois
pas comment reussir a shope le nom des users qui sont tous differents.
On peut peut etre prendre le mot avant le point (.) le mot apres le point,
mais
je ne sais pas comment faire ca...

T'as pas une idee, ya au moins 15000 lignes je peux pas le faire a la
main!!


Merci,
Matthieu


"Daniel" wrote in message
news:ud#
Bonjour.
Essaie :
Sub test()
Dim c As Range
Range("A1:B3").Select
For Each c In Selection
Var = InStr(1, c.Value, "this_word")
If Var > 0 Then
MsgBox c.Address
End If
Next c
End Sub

" Mathew" a $BqD(Brit dans le message de
news:

Hello,

I would like to make a macro which permit to searches a text chain
within


ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range is
the


same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew












Avatar
Jan De Messemaeker
Aucun problème avec le Français mais pourquoi alors adresser ceci à une
dixaine de groupes Anglophones?

Please, Please, do not crosspost.

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
+32-495-300 620
" Mathew" schreef in bericht
news:
Isabelle,

Merci pour ton aide.
Mais je ne vois pas comment on utilise la fct
=SUPPRESPACE(MotCentre(A1;" ";":"))
J'ecris ca ou ?
(Et dans le module ou j'ai copie le code, je dois faire une sub () ou bien
?)

Desole, je suis vraiment nul!!!
Matthieu


"isabelle" wrote in message
news:
bonjour Mathew,

copie cette fonction dans un module,

Function MotCentre(ByVal Chaine$, _
Optional SeparateurX$ = " ", Optional SeparateurY$ = " ")
Dim posX, posY, nbcarT, nbcarX, MotIntérieurDélimité_X
nbcarT = Len(Chaine)
nbcarX = Len(SeparateurX)
posX = Application.Search(SeparateurX, Chaine)
posY = Application.Search(SeparateurY, Chaine, posX)
MotIntérieurDélimité_X = Right(Chaine, nbcarT - posX - nbcarX + 1)
On Error GoTo fin
MotCentre = Left(MotIntérieurDélimité_X, posY - posX - nbcarX)
Exit Function
fin:
MotCentre = MotIntérieurDélimité_X
End Function

et en la combinant avec la fonction SUPPRESPACE, tu auras le résultat
attendu.
=SUPPRESPACE(MotCentre(A1;" ";":"))

isabelle

Salut,

merci pour ta reponse hier sur le news group.
Comme tu a l'air de maitriser, j'aimerai te pose une autre question :

Dans mon tableau, j'ai des cases avec:
Hiroyuki.Ohama:(CI) CHANGE
Yukiko.Kojima:(CI) CHANGE
etc...

(Les espaces du debut y sont aussi)

Et je dois copier le nom des users (par ex :Yukiko.Kojima) dans une
autre


case.
Pour automatiser le truc sur tout le fichier je sais le faire, mais je
ne


vois
pas comment reussir a shope le nom des users qui sont tous differents.
On peut peut etre prendre le mot avant le point (.) le mot apres le
point,


mais
je ne sais pas comment faire ca...

T'as pas une idee, ya au moins 15000 lignes je peux pas le faire a la
main!!




Merci,
Matthieu


"Daniel" wrote in message
news:ud#

Bonjour.
Essaie :
Sub test()
Dim c As Range
Range("A1:B3").Select
For Each c In Selection
Var = InStr(1, c.Value, "this_word")
If Var > 0 Then
MsgBox c.Address
End If
Next c
End Sub

" Mathew" a $BqD(Brit dans le message
de




news:


Hello,

I would like to make a macro which permit to searches a text chain



within

ranges of an excel file.

For ex : If Range (XX) contains "this_word" then....

I can only searche when the text chain is exactly the same.
I would like to be able to do it even if only one word of the range
is






the

same as my text chain.

Does someone knows how to do this ?

Maybe it's a newbee question, sorry.

Thanks
Mathew


















1 2