Results 1 to 10 of 49

Thread: Copy and Paste based on comparisons/Match and calculations of cells in two workbooks

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #26
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    You almost had it right here: https://eileenslounge.com/viewtopic....6a1745#p271427
    You were close to correct.

    I try to explain again what Hans tried to explain ( I think you almost understood ):
    __With Ws1
    ………
    ……….
    …………………
    . Cells(i, "E") ……… .Cells(i, "E")
    __End With

    is almost =
    .....Ws1.Cells(i, "E") …… Ws1.Cells(i, "E")

    You want Ws2 ( for Alertcodes.xlsx ) , not Ws1

    Maybe like
    Code:
               Wtih Ws1
                    If Ws2.Cells(r2, "D") = ">" Then 'calculate the data 1% with column E of AlertCodes.xlsx & add the calculated result with Column E of AlertCodes.xlsx
                        .Cells(i, "K").Value = Ws2.Cells(i, "E").Value - 0.01 * Ws2.Cells(i, "E").Value
                    Else
                        .Cells(i, "K").Value = Ws2.Cells(i, "E").Value + 0.01 * Ws2.Cells(i, "E").Value
                    End If
               End With
    This will also be the same
    Code:
                    If Ws2.Cells(r2, "D") = ">" Then 'calculate the data 1% with column E of AlertCodes.xlsx & add the calculated result with Column E of AlertCodes.xlsx
                        Ws1.Cells(i, "K").Value = Ws2.Cells(i, "E").Value - 0.01 * Ws2.Cells(i, "E").Value
                    Else
                        Ws1.Cells(i, "K").Value = Ws2.Cells(i, "E").Value + 0.01 * Ws2.Cells(i, "E").Value
                    End If
    If this does not work, then you must explain again exactly what you want the macro to do.

    Ws2.Cells(i, "E").Value - 0.01 * Ws2.Cells(i, "E").Value
    and
    Ws2.Cells(i, "E").Value + 0.01 * Ws2.Cells(i, "E").Value
    is 'calculate the data 1% with column E of AlertCodes.xlsx & add the calculated result with Column E of AlertCodes.xlsx




    This was wrong:
    Ws2.Cells(i, "E").Value - 0.01 *.Cells(i, "E").Value
    and
    Ws2.Cells(i, "E").Value + 0.01 * .Cells(i, "E").Value
    It is 'calculate the data 1% with column E of AlertCodes.xlsx & add the calculated result with Column E of 1.xls
    It is the same as
    Ws2.Cells(i, "E").Value - 0.01 *Ws1.Cells(i, "E").Value
    and
    Ws2.Cells(i, "E").Value + 0.01 * Ws1.Cells(i, "E").Value



    ( I never use
    __ With
    __ End With

    because it confuses me.
    But lots of other people, like Hans do use it. Everyone writes codes a bit differently, because all VBA codes can be written in many ways. )





    Also
    Have you seen this ? : https://excelfox.com/forum/showthrea...4565#post14565
    Your macro , Sub STEP6() from here
    https://excelfox.com/forum/showthrea...ll=1#post14562
    and here
    https://eileenslounge.com/viewtopic....271385#p271385
    has the wrong Lr2
    Last edited by DocAElstein; 07-14-2020 at 01:34 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 85
    Last Post: 06-09-2020, 05:58 PM
  2. Copy paste data based on criteria
    By analyst in forum Excel Help
    Replies: 7
    Last Post: 01-13-2014, 12:46 PM
  3. Replies: 4
    Last Post: 12-12-2013, 06:16 PM
  4. Replies: 8
    Last Post: 10-31-2013, 12:38 AM
  5. Replies: 2
    Last Post: 02-11-2013, 08:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •