Conditionally copy paste the data between sheets

Conditionally copy paste the data between sheets
plz see the sample file
sample.xlsb
Sachin SinghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please give this a try...

Sub CopyDataFromSheet5()
Dim ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet, ws5 As Worksheet
Dim cnt As Long, i As Long
Dim lr As Long, dlr As Long
Application.ScreenUpdating = False
Set ws2 = Sheets("Sheet2")
Set ws3 = Sheets("Sheet3")
Set ws4 = Sheets("Sheet4")
Set ws5 = Sheets("Sheet5")
lr = ws5.Cells(Rows.Count, 1).End(xlUp).Row
ws4.Cells.Clear
cnt = ws2.Range("A1").CurrentRegion.Rows.Count - 1
For i = 1 To cnt
    If ws4.Range("A1").Value = "" Then
        dlr = 1
    Else
        dlr = ws4.Range("A" & Rows.Count).End(3)(2).Row
    End If
    ws5.Range("A1:T" & lr).Copy ws4.Range("A" & dlr)
    
Next i

cnt = ws3.Range("A1").CurrentRegion.Rows.Count - 1
For i = 1 To cnt
    If ws4.Range("A1").Value = "" Then
        dlr = 1
    Else
        dlr = ws4.Range("A" & Rows.Count).End(3)(2).Row
    End If
    ws5.Range("A1:T" & lr).Copy ws4.Range("A" & dlr)
Next i

ws4.UsedRange.Sort key1:=ws4.Range("J1"), order1:=xlAscending, Header:=xlNo
Application.ScreenUpdating = True
End Sub

Open in new window

Click the button called "Copy Data" on Sheet4 to run the code.
sample.xlsb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sachin SinghAuthor Commented:
Thnx Neeraj Sir for ur great support
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Sachin!
0
Saqib Husain, SyedEngineerCommented:
You really did not need to loop. This one liner could have done the same job.

Sub copymultiple()
Sheet5.Range("A1").CurrentRegion.EntireRow.Copy Sheet4.Range("A1").Resize( _
    (Sheet2.Range("A1").CurrentRegion.Rows.Count - 1 + _
    Sheet3.Range("A1").CurrentRegion.Rows.Count - 1) * _
    Sheet5.Range("A1").CurrentRegion.Rows.Count)

End Sub

Open in new window

0
Sachin SinghAuthor Commented:
Thnx Saqib Sir for the great info and thnx for the support
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.