Page 5 of 5 FirstFirst ... 345
Results 41 to 49 of 49

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

  1. #41
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    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!!

  2. #42
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    No Problem Doc Sir
    But from now i am only hanging in three forums excelfox,excelforum & eileens lounge
    If i provided the sample file earlier to HansV Sir then this problem will not be occured & from next Time i am looking for a change in the macro
    then sure i will put the code plus sample file too...
    From next time it will not be repeated

  3. #43
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Here is an alternative, just out of interest. Just “for fun”
    It is probably only useful for my later reference, that’s all.

    The main changes are
    _1) I use arrays. ( arr1() , arr2() , arr2B() )
    I do this just from personal choice. I do this because arrays work much faster if you are only interested in values with no cell formatting
    _2) I changed WorksheetFunction.Match to Application.Match , because I do not like to use On Error Resume Next
    I do not need On Error Resume Next for Application.Match , because , if it does not find a match, it does not error. Instead, it returns a VBA error string message, which can be tested for using IsError( __ )
    ( https://excelfox.com/forum/showthrea...ll=1#post14204 )
    _3) I do not use _ With _ End With _ because it confuses me

    I left the original code lines in , ' commented out for comparison

    Here is the alternative: https://excelfox.com/forum/showthrea...ll=1#post14605
    ….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!!

  4. #44
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Problem Solved
    Thnx Alot Doc Sir for Helping me in solving this Problem Sir
    Have a Great Day

  5. #45
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    Macro Correction(iF Condition match then replace the data)

    Hi Experts,

    I am looking for a macro that will do the below things
    Plz see the sample file
    there are 3 files ap.xls & BasketOrder.xlsx & macro.xlsm (macro will be placed in macro.xlsm),both files are located in different places so the path will be hardcoded in the macro so that i can change it as per my needs
    sheet name can be anything


    If column J is BUY of BasketOrder.xlsx then add 1% of column O of ap.xls to column O of ap.xls and compare column O of ap.xls with column L of BasketOrder.xlsx and if column O of ap.xls is smaller than column L of BasketOrder then replace column L of BasketOrder data with column O of ap.xls data(with that added 1% of column O of ap.xls) else do nothing

    Or

    If column J is SELL of BasketOrder.xlsx then subtract 1% of column P of ap.xls to column P of ap.xls and compare column P of ap.xls with column L of BasketOrder.xlsx and if column P of ap.xls is Greater than column L of BasketOrder then replace column L of BasketOrder data with column P data of ap.xls (with that subtract 1% of column P of ap.xls) else do nothing



    Thnx for the Help

    macro will be placed in a seperate file




    This macro i have for this problem but some issue is there
    Code:
    Sub STEP8()
        Application.ScreenUpdating = False
        Dim wb1 As Workbook
        Dim wb2 As Workbook
        Dim ws1 As Worksheet
        Dim ws2 As Worksheet
        Dim TempValue As Double
        
        Dim RowCount1 As Integer
        Dim ColumnCount1 As Integer
        Dim RowCount2 As Integer
        Dim ColumnCount2 As Integer
        Dim BOmyArray() As Variant
        Dim APmyArray() As Variant
        
        BOExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\Files\BasketOrder.xlsx"
        APExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\ap.xls"
        
        Set wb1 = Workbooks.Open(Filename:=APExcellFilePath)
        Set ws1 = wb1.Sheets(1)
        RowCount1 = ws1.UsedRange.Rows.Count
        ColumnCount1 = ws1.UsedRange.Columns.Count
        APmyArray = ws1.Range("A1:U" & ColumnCount1).Value
        wb1.Close SaveChanges:=False
        Set wb1 = Nothing
        
        Set wb2 = Workbooks.Open(Filename:=BOExcellFilePath)
        Set ws2 = wb2.Sheets(1)
        RowCount2 = ws2.UsedRange.Rows.Count
        ColumnCount2 = ws2.UsedRange.Columns.Count
        BOmyArray = ws2.Range("A1:Y" & ColumnCount2).Value
    
        For i = 1 To RowCount2
        TempValue = 0
            For j = 2 To RowCount1
                If (APmyArray(j, 5) = BOmyArray(i, 3)) Then
                  If (BOmyArray(i, 10) = "BUY") Then
                      If (APmyArray(i + 1, 15) <> "") Then
                          TempValue = APmyArray(i + 1, 15) + APmyArray(i + 1, 15) * 0.01
                          If (TempValue < BOmyArray(i, 12)) Then
                              ws2.Activate
                              ws2.Cells(i, 12).Value = TempValue
                          End If
                      End If
                  ElseIf (BOmyArray(i, 10) = "SELL") Then
                      If (APmyArray(i + 1, 15) <> "") Then
                          TempValue = APmyArray(i + 1, 15) - APmyArray(i + 1, 15) * 0.01
                          If (TempValue > BOmyArray(i, 12)) Then
                              ws2.Activate
                              ws2.Cells(i, 12).Value = TempValue
                          End If
                      End If
                  End If
                End If
            Next
        Next
        Application.ScreenUpdating = True
        wb2.Save
        wb2.Close
    End Sub
    Attached Files Attached Files

  6. #46
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Code:
    Public BOExcellFilePath As String
    Public APExcellFilePath As String
    Public Sub ApplciationProgram()
    On Error GoTo ErrorHandler
        Application.ScreenUpdating = False
        Dim wb1 As Workbook
        Dim wb2 As Workbook
        Dim ws1 As Worksheet
        Dim ws2 As Worksheet
        Dim ExcellFilePath As String
        Dim TempValue As Double
        
        Dim RowCount1 As Integer
        Dim ColumnCount1 As Integer
        Dim RowCount2 As Integer
        Dim ColumnCount2 As Integer
        Dim BOmyArray() As Variant
        Dim APmyArray() As Variant
        
        BOExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\BasketOrder.xlsx"
        APExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\ap.xls"
        
        Set wb1 = Workbooks.Open(Filename:=APExcellFilePath)
        Set ws1 = wb1.Sheets(1)
        RowCount1 = ws1.UsedRange.Rows.Count
        ColumnCount1 = ws1.UsedRange.Columns.Count
        APmyArray = ws1.Range("A1:U" & ColumnCount1).Value
        wb1.Close SaveChanges:=False
        Set wb1 = Nothing
        
        Set wb2 = Workbooks.Open(Filename:=BOExcellFilePath)
        Set ws2 = wb2.Sheets(1)
        RowCount2 = ws2.UsedRange.Rows.Count
        ColumnCount2 = ws2.UsedRange.Columns.Count
        BOmyArray = ws2.Range("A1:Y" & ColumnCount2).Value
    
        For i = 1 To RowCount2
        TempValue = 0
            For j = 2 To RowCount1
                If (APmyArray(j, 5) = BOmyArray(i, 3)) Then
                  If (BOmyArray(i, 10) = "BUY") Then
                      If (APmyArray(j, 15) <> "") Then
                          TempValue = APmyArray(j, 15) + APmyArray(j, 15) * 0.01
                          If (TempValue < BOmyArray(i, 12)) Then
                              ws2.Activate
                              ws2.Cells(i, 12).Value = TempValue
                          End If
                      End If
                  ElseIf (BOmyArray(i, 10) = "SELL") Then
                      If (APmyArray(j, 16) <> "") Then
                          TempValue = APmyArray(j, 16) - APmyArray(j, 16) * 0.01
                          If (TempValue > BOmyArray(i, 12)) Then
                              ws2.Activate
                              ws2.Cells(i, 12).Value = TempValue
                          End If
                      End If
                  End If
                End If
            Next
        Next
        Application.ScreenUpdating = True
        
        MsgBox "Program successfully completed "
        Exit Sub
    ErrorHandler:
        MsgBox "UNKNOWN ERROR  - Error# " & Err.Number & " : " & Err.Description
    End Sub

    Problem Solved

  7. #47
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    Clear the data if matches

    https://www.excelforum.com/excel-pro...f-matches.html


    Hi,

    I am looking for a macro that doesnt the things mentioned below


    If column E of book1.xlsb matches with column Z of ap.xls & column U of ap.xls is postive then match column Z of ap.xls with column B of sheet1 of book1.xlsb & if it matches then clear the data in sheet1 of book1.xlsb
    macro will be placed in book1.xlsb so the path should be hardcoded in the macro

    clear the data means we have to clear the data from column C of sheet1 of book1.xlsb (we dont have to delete the data of column A & Column B of sheet1 of book1.xlsb )


    Thnx For the Help
    Attached Files Attached Files

  8. #48
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Problem Solved

  9. #49
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Once again you forgot to tell us how and where you got it Solved




    Moderator” Notice

    **I am Banning you to prevent you making any more postings here of the type you have been making here and elsewhere under hundreds of different user names at many of the English speaking Excel and Office help forums for the last couple of years.

    The type of post that you have been posting suggest that
    _ You may be one person or a !!team of many people working at something organised like a Call Centre.
    ( !! Sometime when you have been “caught” cross posting, you did not know yourself where you cross posted, and asked to be told. ( Or you maybe only wanted to admit to those where you got “caught”) )
    _ You have almost no understanding of the English language
    _ You may not have a computer and may have no access to Excel
    _ You have no interest in Excel or Excel VBA
    _ You have almost no knowledge or interest in any of the questions that you are asking
    _ You may be simply offering a service of posting other peoples questions and supplying them with any answers you get.
    _ You may be part of the development of a question asking and Replying Bot


    _ In some cases, something extremely simple to understand, has been explained to you very many times, in great detail , even graphically, such that even a small mentally handicapped child could understand it and remember it. Despite this, you continually ask exactly that same question over and over again: If you are part of a team interested in only posting questions and taking the answer, then you are very badly organised,
    Or
    There is no real intelligence behind what is producing your questions and posts
    _ One of the things you consistently do after receiving a macro is to delete all explanations, explaining 'comments and all files associated, and indeed it appears as if you try to remove almost all record of the coding and the question and answer. This further encourages the posting of the same or similar questions over and over again.

    Whatever you are attempting to do, it appears to be extremely, almost insanely, inefficient ,
    compared to
    a single person with a computer and Excel, and a minimum of basic Excel VBA knowledge trying to achieve the same.

    The main reason for the ban is
    Whatever you are attempting to do, it is requiring 10-100 times more time than is typically required of helpers at a forum. All indications are that what you are doing will fail to achieve anything, and is therefore a total waste of everyone’s time. At excelfox, the current small number of helpers have only a limited amount of time, but even if we had more members, excelfox would not be the place for you.
    I am totally bored shitless with your Threads that are almost always asking the same thing.
    ## Some of the major forums may be a good place for you to post. There are some senior brain dead morons there who are happy to keep answering the same questions over and over again. Half of them are probably either senile Dement or just plain stupid anyway, and they don’t remember from one day to the next.

    These are some suggestions, from me, on how you should continue
    _ If you intend to continue, regardless of any of my previous suggestions, in postings of the type as you have done in the past, then you should think about making some changes to your wording, introduce some new canned replies, possibly organise a new set of similar questions and post at the major forums, such as mrexcel.com, excelforum.com, ozgrid.com
    _ If you wish to make a career out of posting questions and getting answers without having any real intentions of thinking about anything, then excelfox is not the forum for you to post in. Most of the smaller forums are not the place for you. The larger forums may be able to accommodate you, if you give at least some thought to making it not quite so obvious: Your distinguishing characteristic is that you have been making it much more obvious than others doing the same, do: Many people do the such. At least half the traffic at such forums originates from such. I have passed many people on to such forums and they are making a successful career based on passing on the work done for them by helpers at the major forums. Such is actually encouraged, all be it , not openly, at the major forums.
    _ If you have not understood most of this Moderator Notice , then your first priority should be to improve on your English. Indeed, your apparent understanding and ability in communicating in English suggests that you will achieve nothing whatsoever and fail completely in anything at all involving communicating in English.

    _ If you are, as you sometimes told me via PM, actively working on an important personal problem requiring VBA , then you are doing it totally wrongly: You have been on the project already for at least two years and have a mixed up set of codings produced by many different people. Some work . Some don’t. You have not the slightest idea or understanding of any of the codings. You will never be able to use them to any effect. You are getting an ever increasingly different set of codings with every post you make, and reply you get, which all just confuses the issues further. You are making negative progress, Bro! You are working and going backwards most of the time.
    If , on the other hand, you had a computer, with Excel, and spent a few weeks learning VBA, and then carefully studied all the macros that you have been given, then you would be able to answer most of your further questions, and would have at least a chance of being able to use the codings effectively:-
    1 Month learn VBA and 1 month getting answers, partly alone, partly with help from forums = Finished Success
    2+ Years posting the same and similar questions and just taking the answers = Never Ending Fail

    _ It is unlikely that the macros you have that work will ever be very efficient and will likely be slower than anyone else’s: They will certainly not be the best possible. Giving you better coding has proved to be impossible: It is not possible to pass on better codings because of the ridiculously inefficient way that you are organising whatever it is that you are doing: The person receiving and passing on the coding needs to understand the English language and to understand some basic coding and to understand how to use such better coding. We have tried this a few times, but it proved always completely impossible to do. One example of this is the issue of text files: Because you are mostly dealing with values, the use of text files is almost certainly beneficial and in some cases the only efficient way to proceed. You have completely missed the point on this: You have repeated much work to try to avoid using text files. The problem was, and will never be, the issue of text files themselves. The issue is your total inability or unwillingness to understand anything at all about them.

    Another possibility is that you and/ or yous are simply severally mentally handicapped: If that is the case then, then I am , sincerely, sorry for you, but you have no hope of achieving anything with what you are doing at forums , apart from wasting a lot of other people’s time.



    ##The main purpose of the question section of excelfox is approximately the following:
    _1. Promote and improve the understanding of Excel and Excel VBA.
    _2. Help people who get stuck on a problem and/or help people who are unsure how to proceed in solving a problem using Excel and Excel VBA.

    Your objectives??
    I do not know what the true reason is behind your postings. I can’t believe anything you say is your purpose, since you have lied and contradicted yourself in the past. The only thing we know 100% for sure is that your posting types are not for any of the purposes for which the question section of excelfox is intended.
    You have had the benefit of the doubt given to you now very many times. You have had lots of chances.
    You may be able to continue at some of the major forums, where some people are happy to continue to spend time to answer similar questions from the same source.
    I do not think you will get any more replies to the types of postings you have been making at excelfox or at any other of the smaller English speaking Forums. You are wasting your time making any such posts from now on.
    **I am Banning you, not as any form of punishment, but purely as in the past , it has proven to be the only way to prevent you wasting yours and other peoples time with your postings.
    I do wish you luck and success with what ever it is you are attempting to do. But you should not be doing it at excelfox.
    If you are attempting the personal project that you have told me about via PM, then you are going about it in completely the wrong way.
    If you are trying to make a career of posting other people’s questions and getting answers for them, then you should post mostly at the major forums and organise yourself better: At least have access to Excel on a computer and learn the basics of VBA. If you are trying to make a career of posting other people’s questions and getting answers for them, as many people do, then you have made the mistake of making it too obvious. Many of the senior helpers at the main forums prefer to think that they are helping people rather than doing their work for them. What they don’t know, does not hurt them.


    I will leave all your posts in the main forum for a few weeks. Then I will move them all to the test forum. I will probably further merge them. Eventually I may delete them all.


    Bro, whatever you are trying to do, its not working. Its never going to work. Its just wasting everybody’s time.
    You need first to learn English
    Then get a computer with Microsoft Office.
    Then learn some basic Excel and Excel VBA
    Then start again.
    If you ever come to excelfox again you will have to prove to me that
    _ You are a real person
    _ You are genuinely attempting a personal project and need help
    _ You have a computer with Microsoft Office / Excel installed and that you can, and do, use it, and that you understand basic VBA programming.


    Ref
    https://excelfox.com/forum/showthrea...h-Introduction
    ….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
  •