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 :

Copy & Paste if condition met with add & subtract


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    it
    Inscrit en
    Août 2020
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : Inde

    Informations professionnelles :
    Activité : it
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Août 2020
    Messages : 1
    Par défaut Copy & Paste if condition met with add & subtract
    Hi Experts,
    I am looking for a macro that will do the things mentioned below

    there are 3 files 1.xls & BasketOrder.xlsx & macro.xlsm (macro will be placed in macro.xlsm),both files are loacted in diffrent places so the path will be hardcoded in the macro so that i can change it as per my needs
    sheet name can be anything
    plz see the sample file

    If column C of basketorder.xlsx matches with column B of 1.xls & Column J is BUY then add 0.05 to column D of 1.xls & compare column L of basketorder.xlsx with column D of of 1.xls & if column D of 1.xls is lower then Column L of basketorder.xlsx then replace column L data with column D data OF 1.xls

    If column C of basketorder.xlsx matches with column B of 1.xls & Column J is SELL then subtract 0.05 to column D of 1.xls & compare column L of basketorder.xlsx with column D of of 1.xls & if column D of 1.xls is greater then Column L of basketorder.xlsx then replace column L data with column D data OF 1.xls

    Thnx for the Help
    Fichiers attachés Fichiers attachés

  2. #2
    Expert confirmé
    Homme Profil pro
    retraité
    Inscrit en
    Juin 2012
    Messages
    3 422
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : retraité
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juin 2012
    Messages : 3 422
    Par défaut
    Bonjour,

    Un début de solution, à vérifier et adapter:
    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
    Sub BuySell()
        Dim shBO As Worksheet, sh1 As Worksheet
        Dim kR As Long, kR1 As Long
        Workbooks.Open "BasketOrder.xlsx"
        Set shBO = Sheets("Sheet1")
        Workbooks.Open "1.xls"
        Set sh1 = Sheets("1-Sheet1")
        kR = 1
        shBO.Activate
        With sh1
            Do While Range("C" & kR) <> ""     '--- terminé si cellule vide
                kR1 = kR + 1
                If Range("C" & kR) <> .Range("B" & (kR1)) Then
                    Range("C" & kR).Select
                    MsgBox "Tickers différents sur ligne " & kR
                    Exit Do
                Else
                    If Range("J" & kR) = "BUY" Then '--- Column J is BUY
                        '--- add 0.05 to column D of 1.xls
                        .Range("D" & kR1) = .Range("D" & kR1) + 0.05
                        '--- if column D of 1.xls is lower then Column L of basketorder.xlsx then _
                             replace column L data with column D data OF 1.xls
                        If Range("L" & kR) > .Range("D" & kR1) Then
                            Range("L" & kR) = .Range("D" & kR1)
                        End If
                    ElseIf Range("J" & kR) = "SELL" Then
                        '--- subtract 0.05 to column D of 1.xls
                        .Range("D" & kR1) = .Range("D" & kR1) - 0.05
                        '--- if column D of 1.xls is lower then Column L of basketorder.xlsx then _
                             replace column L data with column D data OF 1.xls
                        If Range("L" & kR) < .Range("D" & kR1) Then
                            Range("L" & kR) = .Range("D" & kR1)
                        End If
                    End If
                End If
                kR = kR + 1
            Loop
        End With
        Set sh1 = Nothing
        Set shBO = Nothing
    End Sub
    Bonne continuation.

Discussions similaires

  1. [E-07] boucle copy paste sous condition sur ligne particuliere
    Par dec3003 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 31/03/2009, 17h36
  2. [E-03] Copie de ligne avec condition de type rechercheV
    Par Lufia dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 27/02/2009, 14h24
  3. Réponses: 0
    Dernier message: 31/12/2008, 15h15
  4. Copie de cellules selon conditions
    Par frisette68 dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 11/03/2008, 20h31
  5. Réponses: 5
    Dernier message: 28/06/2006, 14h02

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