How to modify code

Hello excel world.

I have a problem.

I received updated data from excel web, through power queries table.

Every week the data updates selective rows, depending on the time of the month etc.

Each row of data represents a worksheet historical data.

Now my problem here is this: when I run macro code. it copies and paste the newly selective data from power queries.

But it also copies and paste the old data as well and make a duplicated row.

How can I modify code to prevent this from happening?

See the attached file and code

Bonjour,

Peut il y avoir plus d'une lignes de données différente pour une même date ?

si c'est non,

voici une possibilité,

Sub UpdateSheets()
Dim ws As Worksheet, sh As Worksheet
Dim Rng As Range, c As Range
Dim Lastrow As Integer
Set ws = Sheets("PMI")

Lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row

Set Rng = ws.Range("A2:A" & Lastrow)
For Each c In Rng.Cells
    For Each sh In Sheets
        If sh.Name = c Then
          If Application.CountIf(Sheets(sh.Name).Range("B:B"), ws.Cells(c.Row, "B")) = 0 Then  '<------------------ ici
             Lastrow = sh.Cells(Rows.Count, 2).End(xlUp).Row
             ws.Range("B" & c.Row & ":C" & c.Row).Copy Destination:=sh.Range("B" & Lastrow + 1)
             sh.Range("D" & Lastrow - 1 & ":E" & Lastrow - 1).Copy Destination:=sh.Range("D" & Lastrow + 1)
          End If
        End If
    Next sh
Next c
End Sub

Thank you very much. This code works wonderfully

Rechercher des sujets similaires à "modify code"