Conditionally Copy and Paste of the data

If Column H is greater than Column I and Column K is greater than Column D then paste the data to Sheet3
If Column H is lower than Column I and Column K is lower than Column D then paste the data to Sheet4
Book1.xlsx
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 ConditionalCopy()
Dim wsData As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim lr As Long
Application.ScreenUpdating = False
Set wsData = Sheets("Sheet2")
Set ws3 = Sheets("Sheet3")
Set ws4 = Sheets("Sheet4")
ws3.Cells.Clear
ws4.Cells.Clear
lr = wsData.Cells(Rows.Count, 1).End(xlUp).Row
wsData.Columns(1).Insert
wsData.Range("A2:A" & lr).Formula = "=IF(AND(I2>J2,L2>E2),TRUE,IF(AND(I2<J2,L2<E2),FALSE,""""))"
With wsData.Range("A1").CurrentRegion
    .AutoFilter field:=1, Criteria1:=True
    .SpecialCells(xlCellTypeVisible).Copy ws3.Range("A1")
    ws3.Columns(1).Delete
    .AutoFilter field:=1, Criteria1:=False
    .SpecialCells(xlCellTypeVisible).Copy ws4.Range("A1")
    ws4.Columns(1).Delete
End With
wsData.Columns(1).Delete
wsData.AutoFilterMode = False
Application.ScreenUpdating = True
MsgBox "Data has been copied successfully.", vbInformation
End Sub

Open in new window

Click the button called "Copy Data" on Sheet2 to run the code.
Sachin.xlsm
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
Problem Solved
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Sachin!
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.