IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

[VBA-EXCEL] problème avec ma comparaison


Sujet :

Macros et VBA Excel

  1. #1
    Membre à l'essai
    Inscrit en
    Janvier 2007
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 38
    Points : 10
    Points
    10
    Par défaut [VBA-EXCEL] problème avec ma comparaison
    Bonjour à toutes et à tous,

    j'explique mon problème. J'essaye de faire une liste DVD et donc j'aimerais créer une macro permettant d'ajouter des films dans ma liste. Mais pour cela il faut que je fasse une comparaison du titre à ajouter par rapport à ma liste. Le problème est qu'il ne fait pas bien cette comparaison. Je vais prendre un exemple : J'ai le film l'age de glace. Je veux ajouter dans ma liste le film age. Je ne l'ai pas dans ma liste mais le problème est qu'il me dit que je l'ai car il y a le mot age dans l'age de glace.... donc j'aimerais savoir comment faire pour faire la comparaison sur l'ensemble de la cellule ou trouver un solution pour y remedier....


    voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    Sub Ajouter_un_film()
     
      Dim wk As Workbook
      Dim c As Range ' Resultat de la recherche
      Dim mot As String, sResult As String
      Dim f As Worksheet 'Feuille dans laquelle effectuer la rechercher
      mot = InputBox("saisissez le nom du film à ajouter")
      If Not mot = "" Then
    ' Application.ScreenUpdating = False
        ' Ouverture du classeur :
        Set wk = Workbooks.Open("file://localhost/users/sebneb/Desktop/liste DVD/LISTEDVD.xls")
        'Effectue recherche dans 1° feuille du classser
        Set f = wk.Sheets("feuil2")
        Set c = f.Columns(1).Find(mot)
        If c Is Nothing Then
          Rows(1).Insert Shift:=xlDown
          f.[A1].Value = mot
     
          f.Columns(1).Sort Key1:=Range("A1"), Header:=xlGuess, _
                 OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        Else
          MsgBox ("Ce titre existe déjà")
        End If
      End If
      wk.Close True ' Fermetur de classeur avec sauvegarde...
      ' Application.ScreenUpdating = True  'Réactive l'affichage
    End Sub
    donc si vous avez des idées n'hésitez pas...

    un grand merci d'avance

  2. #2
    Modérateur
    Avatar de AlainTech
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2005
    Messages
    4 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 70
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2005
    Messages : 4 235
    Points : 24 327
    Points
    24 327
    Par défaut
    Citation Envoyé par L'aide en ligne
    Find Method

    Syntax

    expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte)

    expression Required. An expression that returns a Range object.

    What Required Variant. The data to search for. Can be a string or any Microsoft Excel data type.

    After Optional Variant. The cell after which you want to search. This corresponds to the position of the active cell when a search is done from the user interface. Note that After must be a single cell in the range. Remember that the search begins after this cell; the specified cell isn't searched until the method wraps back around to this cell. If this argument isn't specified, the search starts after the cell in the upper-left corner of the range.

    LookIn Optional Variant. Can be one of the following XlFindLookIn constants: xlFormulas, xlValues, or xlNotes.

    LookAt Optional Variant. Can be one of the following XlLookAt constants: xlWhole or xlPart.

    SearchOrder Optional Variant. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.

    SearchDirection Optional Variant. Can be one of the following XlSearchDirection constants: xlNext or xlPrevious. The default value is xlNext.

    MatchCase Optional Variant. True to make the search case sensitive.

    MatchByte Optional Variant. Used only in the Far East version of Microsoft Excel. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.
    A mon avis, il faut que tu t'intéresses au paramètre LookAt.

  3. #3
    Membre à l'essai
    Inscrit en
    Janvier 2007
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 38
    Points : 10
    Points
    10
    Par défaut
    bon alors j'ai essayé mais je ne sais pas quoi mettre après le = dans le code...
    j'ai remplacé cette ligne de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set c = f.Columns(1).Find(mot)
    par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set c = f.Columns(1).Find(mot, lookat:=)
    là je reste sans réponse... si quelqu'un a déjà eu le problème...

  4. #4
    Membre à l'essai
    Inscrit en
    Janvier 2007
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 38
    Points : 10
    Points
    10
    Par défaut
    quelqu'un n'aurait pas un petit indice... svp

    merci d'avance

  5. #5
    Expert éminent sénior

    Homme Profil pro
    Inscrit en
    Août 2005
    Messages
    3 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2005
    Messages : 3 317
    Points : 20 144
    Points
    20 144
    Par défaut
    bonsoir


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set C = f.Columns(1).Find(What:=mot, LookAt:=xlWhole)

    michel

  6. #6
    Membre à l'essai
    Inscrit en
    Janvier 2007
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 38
    Points : 10
    Points
    10
    Par défaut
    merci bien... ça a marché nikel... maintenant je vais essayer de comprendre pourquoi il faut mettre xlwhole...

    encore merci

  7. #7
    Modérateur
    Avatar de AlainTech
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2005
    Messages
    4 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 70
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2005
    Messages : 4 235
    Points : 24 327
    Points
    24 327
    Par défaut
    Whole = la totalité (de la cellule)
    Part = une partie

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] VBA Excel : problème avec la méthode Add
    Par epsilonzero dans le forum MATLAB
    Réponses: 3
    Dernier message: 20/04/2010, 11h02
  2. [XL-2007] fonction vba excel problème avec hh:mm:ss
    Par chantalina dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 21/01/2010, 15h47
  3. Réponses: 6
    Dernier message: 20/02/2007, 17h00
  4. [VBA EXCEL] Problème d'éxécution avec graphiques
    Par RedBurn dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 28/11/2005, 09h55
  5. [VBA Excel] problème de range avec find
    Par loacast dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 23/11/2005, 13h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo