Conditionally copy and paste the data By adding/subtracting by percentage

If column B of sheet1  and column C of sheet3 is same
If column J of sheet3 is BUY then  add 0.01% of column D of sheet1  with itself and paste the data to column L of sheet3 and add 0.1% of column D of sheet1 with itself and paste the data to sheet3 column G
If column J of sheet3 is SELL then  subtract  0.01% of column D of sheet1  with itself and paste the data to column L of sheet3 and subtract 0.1% of column D of sheet1 with itself and paste the data to sheet3 column G
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:
Try this...

Sub PopulateColumnGAndLSheet3()
Dim ws1 As Worksheet, ws3 As Worksheet
Dim x, y, ColL, ColG, dict, Buy, Sell
Dim i As Long, lr As Long
Application.ScreenUpdating = False
Set ws1 = Sheets("Sheet1")
Set ws3 = Sheets("Sheet3")
lr = ws3.Cells(Rows.Count, 1).End(xlUp).Row
Set Buy = CreateObject("Scripting.Dictionary")
Set Sell = CreateObject("Scripting.Dictionary")
x = ws1.Range("A1").CurrentRegion.Value
For i = 2 To UBound(x, 1)
    Buy.Item(x(i, 2)) = x(i, 4) * 1.0001 & "_" & x(i, 4) * 1.001
    Sell.Item(x(i, 2)) = x(i, 4) * (1 - 0.0001) & "_" & x(i, 4) * (1 - 0.001)
Next i
x = ws3.Range("A1:J" & lr).Value
ReDim ColL(1 To lr, 1 To 1)
ReDim ColG(1 To lr, 1 To 1)

For i = 1 To UBound(x, 1)
    If Buy.exists(x(i, 3)) Or Sell.exists(x(i, 3)) Then
        If LCase(x(i, 10)) = "buy" Then
            ColL(i, 1) = Split(Buy.Item(x(i, 3)), "_")(0)
            ColG(i, 1) = Split(Buy.Item(x(i, 3)), "_")(1)
        ElseIf LCase(x(i, 10)) = "sell" Then
            ColL(i, 1) = Split(Sell.Item(x(i, 3)), "_")(0)
            ColG(i, 1) = Split(Sell.Item(x(i, 3)), "_")(1)
        End If
    End If
Next i
ws3.Range("L1").Resize(lr, 1).Value = ColL
ws3.Range("G1").Resize(lr, 1).Value = ColG
Application.ScreenUpdating = True
End Sub

Open in new window

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 alot Neeraj Sir for ur great support
but in the result i am getting after decimal 3 to 4 numbers  after can it be after decimal only two numbers
Sachin SinghAuthor Commented:
I will find the solution  for this,  this problem is not related to this , the code is Perfect
Have a Great Day Sir
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
That's not a big deal.
Change lines#13 and 14 to this...
Buy.Item(x(i, 2)) = Round(x(i, 4) * 1.0001, 2) & "_" & Round(x(i, 4) * 1.001, 2)
Sell.Item(x(i, 2)) = Round(x(i, 4) * (1 - 0.0001), 2) & "_" & Round(x(i, 4) * (1 - 0.001), 2)

Open in new window

Sachin SinghAuthor Commented:
Thnx Neeraj Sir for ur Support
I will open a new post Neeraj Sir Bcoz it is conditional  we have to play with  the decimal bcoz system support second value after decimal in 0.05 or 0.10
this is  something different i dont want to mix this post with another problem
Sachin SinghAuthor Commented:
Neeraj Sir i have modified the file plz look into it and do needful
I have modified the file Sorry Sir but that decimal was creating an issue that y i have modified the file
Sachin SinghAuthor Commented:
Leave this question Neeraj Sir
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.