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

Microsoft Office Discussion :

boucle VBA (recherche à partir d'un nom et copier coller)


Sujet :

Microsoft Office

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 3
    Points : 3
    Points
    3
    Par défaut boucle VBA (recherche à partir d'un nom et copier coller)
    Bonjour à tout le monde,

    je viens de m'inscrire ici, tout nouveau,
    j'ai bloqué sur mon fichier,
    je voulais juste copier le nom de l'hôtel et le tarif de l'agence qui le propose, dans une autre feuille , pour l' tarif je souhaiterai copier celui qui a été proposé par le site officiel de l'hôtel ou bien la première agence qui le propose
    comme j'aurai à faire la même manipulation plusieurs fois par jour , donc je cherche un code Vba, si c'est possible

    le code va parcourir la feuille et copier au fur à mesure les hôtels que j'ai choisis, avec leur tarifs



    VEUILLEZ TROUVER CE QUE JE CHERCHE A PRODUIRE DANS L ONGLET RÉSULTAT

    je vous remercie,
    Cordialement,
    Fichiers attachés Fichiers attachés

  2. #2
    Membre averti Avatar de arosec
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Mai 2009
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2009
    Messages : 167
    Points : 324
    Points
    324
    Par défaut
    Bonsoir,

    J'ai écrit une macro qui tente de transformer et consolider les onglets 23,24, ... dans un onglet unique "Data".
    Il suffit ensuite de consulter le résultat dans le pivot. (voir fichier en pj)

    J'espère que cela pourra t'aider un peu!

    Cdlt,

    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
     
    Option Explicit
     
    Type typHotel
      Nom As String
      Indice As String
      Ville As String
    End Type
     
    Type typPrix
      Source As String
      Prix As String
    End Type
     
    Sub ChargerOngletInternetDansData()
    Dim shSrc As Worksheet
    Dim shDst As Worksheet
    Dim shPiv As Worksheet
    Dim pt As PivotTable
    Dim rSrc As Long
    Dim rDst As Long
    Dim th As typHotel
    Dim tp As typPrix
     
      For Each shDst In ThisWorkbook.Worksheets
        If shDst.Name = "Data" Then Exit For
      Next shDst
      If shDst Is Nothing Then
        Set shDst = ThisWorkbook.Worksheets.Add()
        shDst.Name = "Data"
      End If
      If shDst.Name <> "Data" Then
        Set shDst = ThisWorkbook.Worksheets.Add()
        shDst.Name = "Data"
      End If
     
      'Vider le data
      shDst.Select
      shDst.Cells.Delete
     
      shDst.Cells(1, 1) = "Date"
      shDst.Cells(1, 2) = "Hotel"
      shDst.Cells(1, 3) = "Ville"
      shDst.Cells(1, 4) = "Indice"
      shDst.Cells(1, 5) = "Source"
      shDst.Cells(1, 6) = "Prix"
     
      rDst = 1
     
      For Each shSrc In ThisWorkbook.Worksheets
        rSrc = 0
        If IsNumeric(shSrc.Name) Then
          While rSrc < shSrc.UsedRange.Rows.Count
            rSrc = rSrc + 1
            If shSrc.Cells(rSrc, 1) = "+" Then
              rSrc = rSrc + 1
     
              th.Nom = shSrc.Cells(rSrc, 1)
              rSrc = rSrc + 1
              th.Indice = shSrc.Cells(rSrc, 1)
              rSrc = rSrc + 1
              th.Ville = shSrc.Cells(rSrc, 1)
              rSrc = rSrc + 1
              While Not IsNumericPersonal(shSrc.Cells(rSrc, 1))
                rDst = rDst + 1
     
                tp = decompposeSourcePrix(shSrc.Cells(rSrc, 1))
     
                shDst.Cells(rDst, 1) = shSrc.Name
                shDst.Cells(rDst, 2) = th.Nom
                shDst.Cells(rDst, 3) = th.Indice
                shDst.Cells(rDst, 4) = th.Ville
                shDst.Cells(rDst, 5) = tp.Source
                shDst.Cells(rDst, 6) = tp.Prix
                rSrc = rSrc + 1
              Wend
            End If
          Wend
        End If
      Next shSrc
     
      Set shDst = Nothing
      Set shSrc = Nothing
     
      Set shPiv = ThisWorkbook.Worksheets("Pivot")
      Set pt = shPiv.PivotTables(1)
      pt.RefreshTable
      Set pt = Nothing
      Set shPiv = Nothing
    End Sub
     
    Function IsNumericPersonal(s As String) As Boolean
      s = Trim(s)
      If s = "" Then
        IsNumericPersonal = False
      Else
        IsNumericPersonal = IsNumeric(s)
      End If
    End Function
     
    Function decompposeSourcePrix(s As String) As typPrix
    Dim tp As typPrix
    Dim str As String
    Dim tmp As String
    Dim i As Integer
     
      str = ""
      For i = Len(s) To 1 Step -1
        tmp = Mid(s, i, 1)
        If tmp <> "€" And Not IsNumeric(tmp) Then Exit For
        str = tmp & str
      Next i
      tp.Prix = str
      tp.Source = Replace(s, str, "")
      decompposeSourcePrix = tp
    End Function
    Fichiers attachés Fichiers attachés
    Les ordinateurs sont inutiles. Ils ne savent que donner des réponses.
    Pablo Picasso

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    bonjour,
    je te remercie pour la réponse,
    ton idée est intéressante, mais si je souhaite faire ça sur un mois, ça va devenir trop long, et aussi, j'aurai aimé prendre que le tarif du site internet ou bien celui de Expedia, si aucun n'existe, faut prendre le tarif de l'agence qui vient après

    merci



    Citation Envoyé par arosec Voir le message
    Bonsoir,

    J'ai écrit une macro qui tente de transformer et consolider les onglets 23,24, ... dans un onglet unique "Data".
    Il suffit ensuite de consulter le résultat dans le pivot. (voir fichier en pj)

    J'espère que cela pourra t'aider un peu!

    Cdlt,

    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
     
    Option Explicit
     
    Type typHotel
      Nom As String
      Indice As String
      Ville As String
    End Type
     
    Type typPrix
      Source As String
      Prix As String
    End Type
     
    Sub ChargerOngletInternetDansData()
    Dim shSrc As Worksheet
    Dim shDst As Worksheet
    Dim shPiv As Worksheet
    Dim pt As PivotTable
    Dim rSrc As Long
    Dim rDst As Long
    Dim th As typHotel
    Dim tp As typPrix
     
      For Each shDst In ThisWorkbook.Worksheets
        If shDst.Name = "Data" Then Exit For
      Next shDst
      If shDst Is Nothing Then
        Set shDst = ThisWorkbook.Worksheets.Add()
        shDst.Name = "Data"
      End If
      If shDst.Name <> "Data" Then
        Set shDst = ThisWorkbook.Worksheets.Add()
        shDst.Name = "Data"
      End If
     
      'Vider le data
      shDst.Select
      shDst.Cells.Delete
     
      shDst.Cells(1, 1) = "Date"
      shDst.Cells(1, 2) = "Hotel"
      shDst.Cells(1, 3) = "Ville"
      shDst.Cells(1, 4) = "Indice"
      shDst.Cells(1, 5) = "Source"
      shDst.Cells(1, 6) = "Prix"
     
      rDst = 1
     
      For Each shSrc In ThisWorkbook.Worksheets
        rSrc = 0
        If IsNumeric(shSrc.Name) Then
          While rSrc < shSrc.UsedRange.Rows.Count
            rSrc = rSrc + 1
            If shSrc.Cells(rSrc, 1) = "+" Then
              rSrc = rSrc + 1
     
              th.Nom = shSrc.Cells(rSrc, 1)
              rSrc = rSrc + 1
              th.Indice = shSrc.Cells(rSrc, 1)
              rSrc = rSrc + 1
              th.Ville = shSrc.Cells(rSrc, 1)
              rSrc = rSrc + 1
              While Not IsNumericPersonal(shSrc.Cells(rSrc, 1))
                rDst = rDst + 1
     
                tp = decompposeSourcePrix(shSrc.Cells(rSrc, 1))
     
                shDst.Cells(rDst, 1) = shSrc.Name
                shDst.Cells(rDst, 2) = th.Nom
                shDst.Cells(rDst, 3) = th.Indice
                shDst.Cells(rDst, 4) = th.Ville
                shDst.Cells(rDst, 5) = tp.Source
                shDst.Cells(rDst, 6) = tp.Prix
                rSrc = rSrc + 1
              Wend
            End If
          Wend
        End If
      Next shSrc
     
      Set shDst = Nothing
      Set shSrc = Nothing
     
      Set shPiv = ThisWorkbook.Worksheets("Pivot")
      Set pt = shPiv.PivotTables(1)
      pt.RefreshTable
      Set pt = Nothing
      Set shPiv = Nothing
    End Sub
     
    Function IsNumericPersonal(s As String) As Boolean
      s = Trim(s)
      If s = "" Then
        IsNumericPersonal = False
      Else
        IsNumericPersonal = IsNumeric(s)
      End If
    End Function
     
    Function decompposeSourcePrix(s As String) As typPrix
    Dim tp As typPrix
    Dim str As String
    Dim tmp As String
    Dim i As Integer
     
      str = ""
      For i = Len(s) To 1 Step -1
        tmp = Mid(s, i, 1)
        If tmp <> "€" And Not IsNumeric(tmp) Then Exit For
        str = tmp & str
      Next i
      tp.Prix = str
      tp.Source = Replace(s, str, "")
      decompposeSourcePrix = tp
    End Function

Discussions similaires

  1. Créer une recherche dans excel suivi d'un copier/coller
    Par Phoenix311 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 03/12/2012, 17h19
  2. recherche dans une base de donnees; copier coller via une macro
    Par yannlvr dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/04/2010, 17h58
  3. [XL-2003] VBA EXCEL - reduire le temps d'un copier/coller
    Par hevy75 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 18/05/2009, 23h56
  4. Réponses: 6
    Dernier message: 09/02/2007, 17h24
  5. [VBA] Lancer une form à partir de son nom
    Par truman dans le forum Général VBA
    Réponses: 28
    Dernier message: 18/05/2006, 14h41

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