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. #32
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,378
    Rep Power
    10
    The biggest problem is..
    Since a few weeks you have introduced a new problem for yourself which will help to ensure that you fail in everything: You make many cross post and everyone helping you writes there codes slightly differently. So you are getting into a mixed up chaotic mess of different codlings and are beginning to post many wrong files and incorrect or incomplete macros and explanations of what you want.
    You are getting into a mixed up mess

    I seem to be answering almost the same question over and over again. But it gets harder because you are getting into a mixed up mess and are getting worse and worse at explaining what you want.
    Cross posting bad explanations just makes everything worse. It makes it harder for anyone to help you, and more and more people will get fed up with you and stop helping you
    You think you are clever by secretly finding new places and registering new account usernames to cross post the same or similar question. But it is just creating a total chaos and you are losing control yourself and mixing up macros and files everywhere.

    You can ask the wrong question in a thousand places and still get the wrong answer a thousand times. ( By luck, you might once get the right answer, but you probably would never notice )





    The macro you have posted https://excelfox.com/forum/showthrea...ll=1#post14591 does the following:
    It looks for the data values in column I of Ws1 in column B of Ws2. So the range to be searched is column B in Ws2. The values to be searched for are in column I of Ws1
    When a matched value is found we look at the value in column D of Ws2 at the row where the match occurred. Based on whether or not we have “>” in that cell we will add or subtract 1% to the value in E in Ws2 at the row being considered, that is given by loop variable, i
    This last bit is not what you want
    For example, first we look for 22 (from row I=2) in column B of Ws2. That is found in row 1 of Ws2.
    So
    R2=WorksheetFunction.Match(.Cells(i, "I"), Ws2.[B:B], 0)=1
    In row 2 of Ws2 in the D column is a < so we take the option of
    .Cells(i, "K").Value = Ws2.Cells(i, "E").Value + 0.01 * Ws2.Cells(i, "E").Value
    That code line takes the value in column E at row 2 of Ws1 , which is 200 and adds 1% which is 2, giving you 202, which is not what you want.
    You are pasting in the correct file and correct row. But you are taking the data from the correct file but the wrong row

    What you want it to take the value at the row where the match was found in Ws1, which is 1
    That will give the output of 100 +1 = 101

    The macro does what you asked for:
    If column I of 1.xls matches with column B of Alertcodes.xlsx & column D has < this then calculate the 1% of of column E & add that 1% to column E & the result which will come it will be pasted to column K of 1.xls
    If column I of 1.xls matches with column B of Alertcodes.xlsx & column D has > this then calculate the 1% of of column E & subtract that 1% to column E & the result which will come it will be pasted to column K of 1.xls


    But what you asked for could mean many things and have many different answers. Your explanation was incomplete. You explanation was very bad.





    This was error
    Ws2.Cells(i, "E").Value - 0.01 * Ws2.Cells(i, "E").Value
    This is correction
    Ws2.Cells(R2, "E").Value - 0.01 * Ws2.Cells(R2, "E").Value

    We should be doing the calculations to get the result from the matched row in AlertCodes.xlsx, ( Ws2) , which is given by R2, not i



    This is what you want:
    Question:
    We consider the data values in column I of 1.xls, starting from row 2. Values in column I of 1.xls, starting at row 2, are to be looked for, ( Matched ) in column B of AlertCodes.xlsx
    At the row in AlertCodes.xlsx where the match is found, the matched row, the following is to be done:
    Consider the value in column D of AlertCodes.xlsx at the matched row in AlertCodes.xlsx
    & If column D of AlertCodes.xlsx has this, < , then calculate the 1% of column E of AlertCodes.xlsx & add that 1% to column E of AlertCodes.xlsx in that match row & the result which will come it will be pasted to column K of 1.xls at the row of the considered data value in 1.xls
    Or
    else if column D of AlertCodes.xlsx has this, > , then calculate the 1% of column E of AlertCodes.xlsx & subtract that 1% from column E of AlertCodes.xlsx in the match row & the result which will come it will be pasted to column K of 1.xls at the row of the considered data value in 1.xls


    Solution:
    Here https://excelfox.com/forum/showthrea...ll=1#post14594

    Before:
    _____ Workbook: AlertCodes.xlsx ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K
    1 NSE 22 6 < 100 A GTT
    2 NSE 25 6 < 200 A GTT
    3 NSE 15083 6 < 300 A GTT
    Worksheet: Sheet4 July 13 2020

    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K
    1 Exchange Symbol Series/Expiry Open High Low Prev Close LTP
    2 NSE ACC EQ 1265 1282.7 1246.5 1275.3 1247 22 BUY
    3 NSE ADANIENT EQ 151.85 165.45 151.4 151.85 152.35 25 BUY
    4 NSE ADANIPORTS EQ 348 348 338.5 346.55 338.85 15083 BUY
    Worksheet: 1-Sheet1 13July


    After running macro here https://excelfox.com/forum/showthrea...ll=1#post14594

    _____ Workbook: 1.xls ( Using Excel 2007 32 bit )
    Row\Col A B C D E F G H I J K
    1 Exchange Symbol Series/Expiry Open High Low Prev Close LTP
    2 NSE ACC EQ 1265 1282.7 1246.5 1275.3 1247 22 BUY 101
    3 NSE ADANIENT EQ 151.85 165.45 151.4 151.85 152.35 25 BUY 202
    4 NSE ADANIPORTS EQ 348 348 338.5 346.55 338.85 15083 BUY 303
    Worksheet: 1-Sheet1 13July




    Alan






    1.xls : https://app.box.com/s/38aoip5xi7018y9syt0xe4g04u95l6xk
    AlertCodes.xlsx : https://app.box.com/s/jwpjjut9wt3ej7dbns3269ftlpdr7xsm
    macro.xlsm : https://app.box.com/s/z358r7tbc9hzthi539dlj49jsf4gyg8p

    Corrected macro, Sub STEP6() : https://excelfox.com/forum/showthrea...ll=1#post14594
    Last edited by DocAElstein; 07-15-2020 at 04:06 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
  •