Copie to

brankscaffold

New Member
Joined
Jun 15, 2022
Messages
18
Office Version
  1. 365
Platform
  1. Windows
I got this one off the net, but I can't get it to work quite right.

now only 2 lines are copied and always the same

VBA Code:
Sub rowcopy()
Const FirstRow = 2
Dim rij As Long
Dim n As Long
Dim src As Worksheet
Dim trg As Worksheet
Dim SrcRow As Long
Dim lastRow As Long
                        Set src = Sheets("Ridon 22")
                        Set trg = Sheets("Asindo 22")
                                                        Application.ScreenUpdating = False

                        rij = trg.[A65536].End(xlUp).Row

For n = 5 To Blad1.[A65536].End(xlUp).Row
If Cells(n, "AE").Value = "Asindo" Then
Range(Cells(n, "A"), Cells(n, "AZ")).Copy
trg.Cells(rij, "A").PasteSpecial
 
Rather than waiting for your response and most likely totally redesigning the code, here is a modification to the current code that might work for you.
If you have a lot of data and it is too slow, we will still need to look at a total redesign.

VBA Code:
Sub rowcopy_mod()
    Const FirstRow = 5
    Dim rij As Long
    Dim n As Long
    Dim src As Worksheet
    Dim trg As Worksheet

    Set src = Sheets("Ridon 22")

    Application.ScreenUpdating = False
    
    For n = FirstRow To src.Cells(Rows.Count, "A").End(xlUp).Row
        Set trg = Nothing
        If src.Cells(n, "AE").Value <> "" Then
            On Error Resume Next
            Set trg = Worksheets(src.Cells(n, "AE").Value & " 22")
            If Err = 0 Then
                rij = trg.Cells(Rows.Count, "A").End(xlUp).Row + 1
                With src
                    .Range(.Cells(n, "A"), .Cells(n, "AZ")).Copy
                End With
                trg.Cells(rij, "A").PasteSpecial
            Else
                Err.Clear
                Set trg = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count))
                trg.Name = src.Cells(n, "AE").Value & " 22"
                With src
                    .Range(.Cells(1, "A"), .Cells(4, "AZ")).Copy
                End With
                trg.Cells(1, "A").PasteSpecial
                rij = trg.Cells(Rows.Count, "A").End(xlUp).Row + 1
                With src
                    .Range(.Cells(n, "A"), .Cells(n, "AZ")).Copy
                End With
                trg.Cells(rij, "A").PasteSpecial
            End If
        End If
    Next n
    On Error GoTo 0
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
voorbeeld-klad (3).xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZ
1
2
3
4
5DagweekDatum Debit Factuur Nr.Credit Factuur Nr.OpdrachtbonSoortm1 lang m1 hoogDebit. EenheidDebit PrijsDebit btw%Debit Btw.Debit/uinCredit. EenheidCredit PrijsCredit btw%Credit Btw.Credi/uitOverbtwweekdagbet. TermijnDatumProjectDebit NaamCredit NaamDatumweekBetaald datumBedragBedragweekNog te betalenTotaal BetaaldBetaaldatumBedragBedragweekNog te betalenTotaal Betaaldover
61RDS2022-0001Demontage Steiger163063012,500€ 2,506302,4500€ 1.543,50€ 1.541,00€ 0,0020vr3020-5-2022Gorinchem Kolonel Kavel 5AsindoRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9#WAARDE!€ 1.543,50€ 0,00€ 0,00
72RDS2022-0002Demontage Steiger2630126012,500€ 2,5012602,4500€ 3.087,00€ 3.084,50€ 0,0020vr3020-5-2022Gorinchem Kolonel Kavel 5Ridon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9#WAARDE!€ 3.087,00€ 0,00€ 0,00
8
9
Asindo 22
Cell Formulas
RangeFormula
O6:O7,T6:T7O6=SUM(M6/100*N6)
P6:P7,U6:U7P6=L6*M6+O6*L6
Q6:Q7Q6=SUM(K6)
V6:V7V6=SUM(U6,-P6,-W6)
W6:W7W6=SUM(-O6,T6)
Z6:Z7Z6=WEEKNUM(AC6,21)
AA6:AA7AA6=TEXT(AC6,"DDD")
AM6:AM7AM6=TEXT(AJ6,"mmm")
AN6:AN7,AV6:AV7AN6=WEEKNUM(AJ6,1)
AO6:AO7AO6=SUM(P6,-AP6)
AP6:AP7,AX6:AX7AP6=SUM(AK6:AL6)
AW6:AW7AW6=SUM(U6,-AX6)
K6:K7K6=SUM(I6*J6)
AG6:AG7AG6=SUM(AC6,AB6)
AZ6:AZ7AZ6=SUM(-AP6,AX6)
 
Upvote 0
Rather than waiting for your response and most likely totally redesigning the code, here is a modification to the current code that might work for you.
If you have a lot of data and it is too slow, we will still need to look at a total redesign.

VBA Code:
Sub rowcopy_mod()
    Const FirstRow = 5
    Dim rij As Long
    Dim n As Long
    Dim src As Worksheet
    Dim trg As Worksheet

    Set src = Sheets("Ridon 22")

    Application.ScreenUpdating = False
   
    For n = FirstRow To src.Cells(Rows.Count, "A").End(xlUp).Row
        Set trg = Nothing
        If src.Cells(n, "AE").Value <> "" Then
            On Error Resume Next
            Set trg = Worksheets(src.Cells(n, "AE").Value & " 22")
            If Err = 0 Then
                rij = trg.Cells(Rows.Count, "A").End(xlUp).Row + 1
                With src
                    .Range(.Cells(n, "A"), .Cells(n, "AZ")).Copy
                End With
                trg.Cells(rij, "A").PasteSpecial
            Else
                Err.Clear
                Set trg = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count))
                trg.Name = src.Cells(n, "AE").Value & " 22"
                With src
                    .Range(.Cells(1, "A"), .Cells(4, "AZ")).Copy
                End With
                trg.Cells(1, "A").PasteSpecial
                rij = trg.Cells(Rows.Count, "A").End(xlUp).Row + 1
                With src
                    .Range(.Cells(n, "A"), .Cells(n, "AZ")).Copy
                End With
                trg.Cells(rij, "A").PasteSpecial
            End If
        End If
    Next n
    On Error GoTo 0
   
    Application.ScreenUpdating = True
   
End Sub
thanks and sorry for the delay. i'm going to try it now. So much has happened in my life at once that I didn't have time for anything for a while
 
Upvote 0
it looks much better already, create new worksheet with correct name :)
only 1 line was copied to asindo

Worksheet Ridon
voorbeeld-klad (3).xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZ
1Invullen#VERW!
2Niet invullen
3Gewerkt CrediteurAEDebiteur/uit tegoedCrediteur/in tegoed/ klantFactuur gegevensVervaldatumdebiteuren betaald / uitcrediteuren betaald /inTotaal Credit Betaald
4DagweekDatum Debit Factuur Nr.Credit Factuur Nr.OpdrachtbonSoortm1 lang m1 hoogDebit. EenheidDebit PrijsDebit btw%Debit Btw.Debit/uinCredit. EenheidCredit PrijsCredit btw%Credit Btw.Credi/uitOverbtwweekdagbet. TermijnDatumProjectDebit NaamCredit NaamDatumweekBetaald datumBedragBedragweekNog te betalenTotaal BetaaldBetaaldatumBedragBedragweekNog te betalenTotaal Betaaldover
51RDS2022-0001Demontage Steiger163063012,500€ 2,506302,4500€ 1.543,50€ 1.541,00€ -20vr3020-5-2022Gorinchem Kolonel Kavel 5AsindoRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9####€ 1.543,50€ 0,00€ 0,00
62RDS2022-0002Demontage Steiger2630126012,500€ 2,5012602,4500€ 3.087,00€ 3.084,50€ -20vr3020-5-2022Gorinchem Kolonel Kavel 5edRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9####€ 3.087,00€ 0,00€ 0,00
73RDS2022-0003Demontage Steiger163063012,500€ 2,506302,4500€ 1.543,50€ 1.541,00€ -20vr3020-5-2022Gorinchem Kolonel Kavel 5pietRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9####€ 1.543,50€ 0,00€ 0,00
8 4RDS2022-0004Demontage Steiger5630315012,500€ 2,5031502,4500€ 7.717,50€ 7.715,00€ -20vr3020-5-2022Gorinchem Kolonel Kavel 5HansRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9####€ 7.717,50€ 0,00€ 0,00
95RDS2022-0005Demontage Steiger3635190512,500€ 2,5019052,4500€ 4.667,25€ 4.664,75€ -20vr3020-5-2022Gorinchem Kolonel Kavel 5AsindoRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9####€ 4.667,25€ 0,00€ 0,00
105RDS2022-0006Demontage Steiger4640256012,500€ 2,5025602,4500€ 6.272,00€ 6.269,50€ -20vr3020-5-2022Gorinchem Kolonel Kavel 5AsindoRidon19-6-202212€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9####€ 6.272,00€ 0,00€ 0,00
Ridon 22
Cell Formulas
RangeFormula
L1L1=SUM(#REF!)
O5:O10,T5:T10O5=SUM(M5/100*N5)
P5:P10,U5:U10P5=L5*M5+O5*L5
Q5:Q10Q5=SUM(K5)
V5:V10V5=SUM(U5,-P5,-W5)
W5:W10W5=SUM(-O5,T5)
Z5:Z10Z5=WEEKNUM(AC5,21)
AA5:AA10AA5=TEXT(AC5,"DDD")
AM5:AM10AM5=TEXT(AJ5,"mmm")
AN5:AN10AN5=WEEKNUM(AJ5,1)
AO5:AO10AO5=SUM(P5,-AP5)
AP5:AP10,AX5:AX10AP5=SUM(AK5:AL5)
AW5:AW10AW5=SUM(U5,-AX5)
K5:K10K5=SUM(I5*J5)
AG5:AG10AG5=SUM(AC5,AB5)
AZ5:AZ10AZ5=SUM(-AP5,AX5)



Worksheet Asindo
voorbeeld-klad (3).xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAX
3Gewerkt CrediteurAEDebiteur/uit tegoedCrediteur/in tegoed/ klantFactuur gegevensVervaldatumdebiteuren betaald / uitcrediteuren betaald /in
4DagweekDatum Debit Factuur Nr.Credit Factuur Nr.OpdrachtbonSoortm1 lang m1 hoogDebit. EenheidDebit PrijsDebit btw%Debit Btw.Debit/uinCredit. EenheidCredit PrijsCredit btw%Credit Btw.Credi/uitOverbtwweekdagbet. TermijnDatumProjectDebit NaamCredit NaamDatumweekBetaald datumBedragBedragweekNog te betalenTotaal BetaaldBetaaldatumBedragBedragweekNog te betalenTotaal Betaald
51RDS2022-0001Demontage Steiger163063012,500€ 2,506302,4500################€ -20vr30########Gorinchem Kolonel Kavel 5AsindoRidon########12€ 0,00€ 0,00jan0€ 2,50€ 0,000-0-0€ 0,000-0-9################€ 0,00
Asindo 22
Cell Formulas
RangeFormula
K5K5=SUM(I5*J5)
O5,T5O5=SUM(M5/100*N5)
P5,U5P5=L5*M5+O5*L5
Q5Q5=SUM(K5)
V5V5=SUM(U5,-P5,-W5)
W5W5=SUM(-O5,T5)
Z5Z5=WEEKNUM(AC5,21)
AA5AA5=TEXT(AC5,"DDD")
AG5AG5=SUM(AC5,AB5)
AM5AM5=TEXT(AJ5,"mmm")
AN5AN5=WEEKNUM(AJ5,1)
AO5AO5=SUM(P5,-AP5)
AP5,AX5AP5=SUM(AK5:AL5)
AW5AW5=SUM(U5,-AX5)
 
Upvote 0
I have adjusted this.

now it must be checked if there are no duplicates.
on the basis of four rows that may not be equal in the same row with less, these must be added to the worksheet. not the same with four.
(B,E, H, AD) these are the values for checking

VBA Code:
For n = FirstRow To src.Cells(Rows.Count, "AE").End(xlUp).Row
        Set trg = Nothing
        If src.Cells(n, "AE").Value <> "" Then
            On Error Resume Next
            Set trg = Worksheets(src.Cells(n, "AE").Value & " 22")
            If Err = 0 Then
                rij = trg.Cells(Rows.Count, "E").End(xlUp).Row + 1
 
Upvote 0
If you are saying that if the current row has the same value in columns B, E, H & AD, then don't copy that row, then confirm that is the case and I will modify the code.
If you want full duplicate checking (ie not just this row with the previous row) you will need to open a new thread.
 
Upvote 0
If you are saying that if the current row has the same value in columns B, E, H & AD, then don't copy that row, then confirm that is the case and I will modify the code.
If you want full duplicate checking (ie not just this row with the previous row) you will need to open a new thread.
yes please :) it is the case
 
Upvote 0
See if this does what you need.

VBA Code:
Sub rowcopy_mod_v02()
   
    Const FirstRow = 5
    Dim rij As Long
    Dim n As Long
    Dim src As Worksheet
    Dim trg As Worksheet
    Dim OKToCopy As String

    Set src = Sheets("Ridon 22")

    Application.ScreenUpdating = False
   
    For n = FirstRow To src.Cells(Rows.Count, "AE").End(xlUp).Row
        OKToCopy = "N"
        Set trg = Nothing
        If src.Cells(n, "AE").Value <> "" Then
            If n = FirstRow Then
                OKToCopy = "Y"
            ElseIf src.Cells(n, "B").Value <> src.Cells(n - 1, "B").Value Then
                OKToCopy = "Y"
            ElseIf src.Cells(n, "E").Value <> src.Cells(n - 1, "E").Value Then
                OKToCopy = "Y"
            ElseIf src.Cells(n, "H").Value <> src.Cells(n - 1, "H").Value Then
                OKToCopy = "Y"
            ElseIf src.Cells(n, "AD").Value <> src.Cells(n - 1, "AD").Value Then
                OKToCopy = "Y"
            Else
                OKToCopy = "N"
            End If
           
            If OKToCopy = "Y" Then
                    On Error Resume Next
                    Set trg = Worksheets(src.Cells(n, "AE").Value & " 22")
                    If Err <> 0 Then
                        Err.Clear
                        Set trg = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count))
                        trg.Name = src.Cells(n, "AE").Value & " 22"
                        With src
                            .Range(.Cells(1, "A"), .Cells(4, "AZ")).Copy
                        End With
                        trg.Cells(1, "A").PasteSpecial
                    End If
                    rij = trg.Cells(Rows.Count, "AE").End(xlUp).Row + 1
                    With src
                        .Range(.Cells(n, "A"), .Cells(n, "AZ")).Copy
                    End With
                    trg.Cells(rij, "A").PasteSpecial
            End If
        End If
    Next n
    On Error GoTo 0
   
    Application.ScreenUpdating = True
   
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top