MS Office Forum / Word / Programming / March 2005
Comparaison method for Range
|
|
Thread rating:  |
Mathew - 30 Mar 2005 08:38 GMT 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
Daniel - 30 Mar 2005 09:00 GMT 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
> Hello, > [quoted text clipped - 13 lines] > Thanks > Mathew Mathew - 31 Mar 2005 03:30 GMT 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
> Bonjour. > Essaie : [quoted text clipped - 26 lines] > > Thanks > > Mathew isabelle - 31 Mar 2005 03:48 GMT 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
Mathew a écrit :
> Salut, > [quoted text clipped - 58 lines] >>>Thanks >>>Mathew Mathew - 31 Mar 2005 06:46 GMT 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
> bonjour Mathew, > [quoted text clipped - 84 lines] > >>>Thanks > >>>Mathew Jan De Messemaeker - 31 Mar 2005 14:08 GMT 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
> Isabelle, > [quoted text clipped - 104 lines] > > >>>Thanks > > >>>Mathew isabelle - 31 Mar 2005 14:27 GMT bonjour Mathew,
>Et je dois copier le nom des users (par ex :Yukiko.Kojima) dans une >autre case. la formule doit etre mis dans cette autre case.
et Function MotCentre(ByVal..... etc tu la copie tel quel dans un module de visual basic, ce n'est pas une Sub mais une Function personnalisé, qui sera disponnible (une fois copier) au menu, Isertion, Function, catégorie Personnalisées
isabelle
Mathew a écrit :
> Isabelle, > [quoted text clipped - 114 lines] >>>>>Thanks >>>>>Mathew Daniel - 31 Mar 2005 08:20 GMT 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
> Salut, > [quoted text clipped - 58 lines] >> > Thanks >> > Mathew anonymousA - 30 Mar 2005 09:11 GMT 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
"Mathew" a écrit :
> Hello, > [quoted text clipped - 13 lines] > Thanks > Mathew Cl?ment Marcotte - 30 Mar 2005 15:21 GMT Écris donc en français, maudit colonisé.
Jan De Messemaeker - 30 Mar 2005 20:41 GMT 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
> ?cris donc en fran?ais, maudit colonis?.
|
|
|