+ Reply to Thread
Results 1 to 11 of 11

Macro to sort and paste data in specific cells

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Angry Macro to sort and paste data in specific cells

    Hello,

    I am completely new to macros, and I have been watching videos for the past week to figure this out. No luck

    I need to paste data from the workbook "ADB" to the "Volume" workbook, which are both attatched. "ADB" has 3 columns: account #, item #, and case sales. The only data I need to copy from "ADB" is the data from columns B & C. Column A is simply the account number that the data belongs too. Column B has the item #, and C has the amount of cases sold for that item #.

    I would like to copy data from columns B & C in "ADB", and paste it into the "Volume" WB. I would like a macro to put the cases sold data for each item # from "ADB" under the correct item # in the "Volume" WB, for each store.

    The first store in the "Volume" WB is #1111 (Cardenas Market #7). In the "ADB" WB, you will notice #1111 carries 18 different items out of the 24 total listed in row 3 of the "Volume" WB.

    I am sure there is an advanced macro that could do all of the stores at once. However, I would just be happy with a macro that could do each store 1 by 1. It would still be faster than how we are doing it now.

    This was the tutorial I was following, and had no luck.
    http://www.youtube.com/watch?v=_sbTZ...eature=mh_lolz

    Thanks in advance for all of your help. I have a feeling this is very simple, I just can't figure it out.

    ADB.xlsVolume.xls
    Last edited by JBeaucaire; 07-06-2012 at 04:44 PM. Reason: Corrected thread title to topic only

  2. #2
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Macro to sort and paste data in specific cells

    @planbms

    Welcome to the forum.

    Put the code into a standard module in the Volume.xls wbook. Having tested the code then checked some of the results I can understand your frustration with the task.

    This is one way, there may well be formulas that can do the same job but this works for me. Let me know how you get on.
    Please Login or Register  to view this content.
    hth

    gmk



    Click the * below the post to say thanks and remember to mark the thread as solved if answered satisfactorily.

  3. #3
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Macro to sort and paste data in specific cells

    @planbms

    As I said there would probably be a formula solution for this as well. This works in E2003, I don't use E2007 and there may be differences.
    In your Volume.xls enter the formula into "C4" using CTRL + SHIFT and ENTER to get something like {=INDEX.......))}. If done correctly you will see the curly brackets. Then drag across to "AC3" and down to fill each of the required cells.

    I have also improved the speed of the macro. So you now have 2 solutions. Try them and let me know.

    Cell formula
    Please Login or Register  to view this content.
    Macro
    Please Login or Register  to view this content.

    hth

    gmk



    Click the * below the post to say thanks and remember to mark the thread as solved if answered satisfactorily.

  4. #4
    Registered User
    Join Date
    07-06-2012
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to sort and paste data in specific cells

    WOW this is the 2nd most amazing thing I have ever seen! First is the birth of my son of course. THANKS VERY MUCH!

    FYI...I am using the first code provided...

    A couple questions for you...1, how does this work? And 2, if I change the file name of "ADB" to something else, will I have to change it in the macro as well since it looks as if it is looking for the file name? Does it look for the account number, then item number, and then dump the case sales there?

    I have different markets (different account numbers) as well that have their own sales data. Everything is in the same format though. This is just one market. I tried to read the code and make sense of it, but if you could tell me what the macro is calling for, or referencing, I will know how to adjust it for the other accounts if need be. Once I see what it is doing, I can grasp it. Again, THANKS FOR YOUR TIME. This is great.

  5. #5
    Registered User
    Join Date
    07-06-2012
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to sort and paste data in specific cells

    And how do I "like" your post?

  6. #6
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Macro to sort and paste data in specific cells

    @planbms

    I'm pleased the code worked for you... but which?

    I am using the first code provided...
    Is that the first code in the first post or the first code in the second post?

    If you can clarify whether you are using the formula or macro I will explain the formula or annotate the macro for you.

    The formula looks complicated but isn't really - it's full of references to the ADB file which are a bit long winded. If you wish I'll give you a little tutor on how to construct it so you can employ similar for your other accounts. The macro is also easily adapted for other uses.

    Let me know.

    gmk

  7. #7
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Macro to sort and paste data in specific cells

    @planbms

    You asked how does it work. If you meant the formula then…

    The complete formula…
    Please Login or Register  to view this content.
    But first, the core…
    Please Login or Register  to view this content.
    What the core formula in cell "C4" of the parent wb is saying is find Me an exact match of Customer id "$A4" and Product id "C$3" from columns "A" and "B" in the source wb.
    If there is a match, get the position, INDEX (row, [column]) of the match and return the value of that row from the target array ("C").
    Note, references to columns aren't necessary here as we only define one column "C" in the target array and column is therefore assumed to be "1".

    To finish off...
    Outside of the core is "IF(ISNA(…..)))". This is useful because MATCH will return "N/A" if a match isn't found and IF(ISNA simply says return a result if there is a match or leave Me blank.
    Note the manner in which the 'what to match' cells are referenced i.e. absolute column for customer id ("$A4") and absolute row for product id ("C$3").
    And not forgetting the "=" and curly brackets... there you have it.
    So the formula when broken down is very simple but looks mega because it is padded out with lengthy wsheet references then doubled in length again by the IF N/A error function.

    If you would like further assistance to either create this formula or adapt it for use in other accounts then don't hesitate, PM me. Just being cautious, never divulge sensitive data on the internet, even in a PM.

    Thank you for the rep and comment, they are much appreciated. Please remember to use Thread Tools and mark the thread Solved if you have the required answer.

    hth

    gmk

  8. #8
    Registered User
    Join Date
    07-06-2012
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to sort and paste data in specific cells

    Sorry...I am using the first macro. Please let me know how that works. Since I get a new report every month, do I need to change the file name to "ABD" so the macro can locate the correct report?

  9. #9
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Macro to sort and paste data in specific cells

    @planbms

    As long as we come back to the thread at the end, I will PM you with a guide on how it works and how to adapt it for other accounts.

    gmk

  10. #10
    Registered User
    Join Date
    07-06-2012
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to sort and paste data in specific cells

    I actually figured it out today, and it's working perfect. Once again, I would like to thank you for all of your help.

    I will mark this solved!

  11. #11
    Forum Contributor
    Join Date
    04-12-2012
    Location
    MD, England
    MS-Off Ver
    Excel 2003
    Posts
    142

    Re: Macro to sort and paste data in specific cells

    @planbms

    Well done. I was just attending to some other thread and was going to start the task shortly. You have saved me some time. Thanks.

    gmk

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1