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 :

Problème recherche d'une valeur avec Find


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2017
    Messages : 57
    Par défaut Problème recherche d'une valeur avec Find
    Bonjour à tous,

    Mon code VBA recherche des valeurs dans un certain range avec Find, cela fonctionne très bien avec du texte mais j'ai un problème lorsque je recherche des nombres, le code me retourne yLoc=Nothing alors que le nombre est bien present dans le range scanné...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    yLoc = ActiveSheet.Range([E13], [E13].End(xlToRight)).Find(What:=PlotForm.TimeList.List(t), lookat:=xlWhole).Select
    D'où le problème peut-il venir ? Merci

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    J'ai eu un problème similaire il y a peu de temps, cependant il serait préférable d'avoir ton code complet pour vérifier si l'origine du problème est la même que moi.

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2017
    Messages : 57
    Par défaut
    Je viens de trouver mon erreur, pour les nombres, il faut ajouter LookIn:=xlValues...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    yLoc = ActiveSheet.Range([E13], [E13].End(xlToRight)).Find(What:=PlotForm.TimeList.List(t), lookat:=xlWhole, LookIn:=xlValues)

  4. #4
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2017
    Messages : 57
    Par défaut
    En Fait même avec le LookIn, ca ne marche qu'une fois sur 10... Le code est assez long et se base sur un UserForm... Le voici:

    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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    Dim i As Long
        Dim j As Long
        Dim l As Long
        Dim u As Long
        Dim t As Long
        Dim counter As Integer
        Dim x As Range
        Dim y As Range
        Dim Cell As Range
        Dim cht As Object
        Dim srs As Series
        Dim rng As Range
        Dim c As Integer
        Dim co
        Dim num As Integer
        Dim Cpt As Integer
        Dim CptSh As Integer
        Dim srscnt As Integer
        Dim xLoc As Range
        Dim yLoc As Range
        Dim xmin As Variant
        Dim xmax As Variant
        Dim hmin1 As Variant
        Dim hmax1 As Variant
        Dim ymin1 As Variant
        Dim ymax1 As Variant
        Dim hmin2 As Variant
        Dim hmax2 As Variant
        Dim ymin2 As Variant
        Dim ymax2 As Variant
        Dim xlabel As String
        Dim ylabel As String
        Dim yunit As String
        Dim yunit1 As String
        Dim yunit2 As String
        Dim shminmax As Worksheet
     
        CptSh = ActiveWorkbook.Sheets.Count
     
    'Opens a new sheet to find axis extrema and units
        Set shminmax = Sheets.Add(After:=Sheets(Sheets.Count))
        shminmax.name = "MinMax"
     
    'Selects column of selected choice for abscissa axis
        For l = 1 To CptSh
            Sheets(l).Activate
            For i = 0 To PlotForm.ChoiceList.ListCount - 1
                If PlotForm.ChoiceList.Selected(i) = True Then
                    If PlotForm.ChoiceList.List(i) = Sheets(l).name Then
                        Set xLoc = ActiveSheet.Range([C14], [D14]).Find(What:=PlotForm.xChoice.Text)
                            If Not xLoc Is Nothing Then
                                ActiveSheet.Range([C14], [D14]).Find(What:=PlotForm.xChoice.Text).Select
                                ActiveCell.Offset(1, 0).Select
                                Set x = Range(ActiveCell, ActiveCell.End(xlDown))
                                xlabel = PlotForm.xChoice.Text
                                xmin = WorksheetFunction.Min(x)
                                xmax = WorksheetFunction.Max(x)
                            End If
                    End If
                End If
            Next i
        Next l
     
    'Plots all y against x
        Set cht = ActiveWorkbook.ActiveSheet.ChartObjects.Add(Left:=350, Width:=400, Top:=30, Height:=275)
     
        'Chart settings
            With cht
     
        .Chart.ChartType = xlXYScatterLinesNoMarkers
     
                'Chart Title
                    .Chart.HasTitle = True
                    If PlotForm.EnterTitle.Text <> "" Then
                        .Chart.ChartTitle.Text = PlotForm.EnterTitle.Text
                    End If
                    .Chart.ChartTitle.Font.name = "Arial"
                    .Chart.ChartTitle.Font.FontStyle = "Bold"
                    .Chart.ChartTitle.Font.Size = 10
     
                'Chart Legend
                    .Chart.Legend.Position = xlBottom
                    .Chart.Legend.AutoScaleFont = False
                    .Chart.Legend.Font.name = "Arial"
                    .Chart.Legend.Font.Size = 7
     
                'Chart Axis
                    'Abscissa Axis
                    .Chart.Axes(xlCategory).HasTitle = True
                    .Chart.Axes(xlCategory).AxisTitle.Font.Size = 8
                    .Chart.Axes(xlCategory).AxisTitle.Text = xlabel
                    .Chart.Axes(xlCategory).MinimumScale = xmin
                    .Chart.Axes(xlCategory).MaximumScale = xmax
     
                    'Ordinate Axis
                    'For l = 1 To CptSh
                    'Sheets(l).Activate
                    '    For j = 0 To PlotForm.yChoice.ListCount - 1
                    '        If PlotForm.yChoice.Selected(j) = True Then
                    '            If Split(PlotForm.yChoice.List(j), "_")(0) = Sheets(l).name Then
                    '                Set yLoc = ActiveSheet.Cells.Find(What:=Split(PlotForm.yChoice.List(j), "_")(1))
                    '                    If Not yLoc Is Nothing Then
                    '                        ActiveSheet.Cells.Find(What:=Split(PlotForm.yChoice.List(j), "_")(1)).Select
                    '                        yunit = ActiveCell.Offset(1, 0).Value
                    '                        Sheets("MinMax").Range("E" & j + 1).Value = yunit
                    '                    End If
                    '            End If
                    '        End If
                    '    Next j
                    'Next l
     
                    'Sheets("MinMax").Activate
                    'If IsEmpty(Range("E1")) Then
                    '    yunit1 = ActiveSheet.Range("E1").End(xlDown).Value
                    'Else
                    '    yunit1 = ActiveSheet.Range("E1").Value
                    'End If
     
                    'Settings for ordinate axis series and scale
                    For l = 1 To CptSh
                    Sheets(l).Activate
                        For i = 0 To PlotForm.ChoiceList.ListCount - 1
                            If PlotForm.ChoiceList.Selected(i) = True Then
                                If PlotForm.ChoiceList.List(i) = Sheets(l).name Then
                                    For t = 0 To PlotForm.TimeList.ListCount - 1
                                        If PlotForm.TimeList.Selected(t) = True Then
                                            Set yLoc = ActiveSheet.Range([E13], [E13].End(xlToRight)).Find(What:=PlotForm.TimeList.List(t), lookat:=xlWhole, LookIn:=xlValues)
                                            If Not yLoc Is Nothing Then
                                                ActiveSheet.Range([E13], [E13].End(xlToRight)).Find(What:=PlotForm.TimeList.List(t), lookat:=xlWhole, LookIn:=xlValues).Select
                                                ylabel = ActiveCell.Offset(1, 0).Value
                                                ActiveCell.Offset(2, 0).Select
                                                Set y = Range(ActiveCell, ActiveCell.End(xlDown))
     
                                                srscnt = .Chart.SeriesCollection.Count
     
                                                With cht
                                                    'If yunit1 <> yunit2 Then
                                                    '    Set srs = .Chart.SeriesCollection.NewSeries
                                                    '    srscnt = srscnt + 1
                                                    '        .Chart.SeriesCollection(srscnt).Select
                                                    '        .Chart.SeriesCollection(srscnt).AxisGroup = 2
                                                    '        .Chart.Axes(xlValue, xlSecondary).Select
                                                    '            hmin2 = WorksheetFunction.Min(y)
                                                    '            hmax2 = WorksheetFunction.Max(y)
                                                    '            Sheets("MinMax").Range("C" & j + 1).Value = hmin2
                                                    '            Sheets("MinMax").Range("D" & j + 1).Value = hmax2
                                                    '    With srs
                                                    '        .XValues = x
                                                    '        .Values = y
                                                    '        .name = PlotForm.yChoice.List(j)
                                                    '    End With
                                                    'Else
                                                        Set srs = .Chart.SeriesCollection.NewSeries
                                                        srscnt = srscnt + 1
                                                            'hmin1 = WorksheetFunction.Min(y)
                                                            'hmax1 = WorksheetFunction.Max(y)
                                                            'Sheets("MinMax").Range("A" & i + 1).Value = hmin1
                                                            'Sheets("MinMax").Range("B" & i + 1).Value = hmax1
                                                        With srs
                                                            .XValues = x
                                                            .Values = y
                                                            .name = ylabel & " " & PlotForm.TimeList.List(t) & [L7].Value
                                                        End With
                                                    'End If
                                                End With
                                            End If
                                        End If
                                    Next t
                                End If
                            End If
                        Next i
                    Next l

  5. #5
    Invité
    Invité(e)
    Par défaut
    En effet le problème est peut-être le même que celui que j'ai eu. Il est possible (je n'en suis absolument pas sur) que le problème vient du fait que tu utilises plusieurs find différents. Regarde ce qui a été dit ici (en particulier le dernier post) : https://www.developpez.net/forums/d1...tion-findnext/

  6. #6
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2017
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2017
    Messages : 57
    Par défaut
    Je viens de me rendre compte qu'il ne trouve que les entiers, pas les décimaux... Bizarre...

  7. #7
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Billets dans le blog
    8
    Par défaut re
    la raison en est toute simple
    c'est pas xlwhole mais xlpart
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

Discussions similaires

  1. [XL-MAC 2011] Recherche d'une date avec find
    Par Holycat dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 09/10/2016, 18h55
  2. [Toutes versions] Confusion de résultats dans recherche des occurrences d'une valeur avec Find sur des dates
    Par iperkut dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 08/11/2011, 19h07
  3. [XL-2010] Recherche d'une valeur avec la copie
    Par zoltix dans le forum Excel
    Réponses: 2
    Dernier message: 08/08/2010, 14h23
  4. problem avec la recherche d'une valeur dans les table
    Par anilane dans le forum Bases de données
    Réponses: 6
    Dernier message: 25/05/2007, 19h35
  5. [VBA-E]Recherche d'une valeur avec la colonne comme variable
    Par Corlo dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 25/04/2007, 09h21

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