+ Reply to Thread
Results 1 to 55 of 55

VBA code to list all products from each customer in one note

  1. #1
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Exclamation VBA code to list all products from each customer in one note

    I am new to VBA programming, I need a VBA code which list all products purchase (Column I) by each customer(columnn G) in one row. It should add list name only once if there are multiple products purchased by same customer. For example output note should be like

    Claire Gute - FUR-BO-10001798
    FUR-CH-10000454


    I have a similar problem but can't share the sheet due to access issues outside work. Sample excel sheet attached.
    Attached Files Attached Files
    Last edited by Jimmy1709; 06-10-2019 at 08:44 PM.

  2. #2
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Sheet attached.

  3. #3
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,282

    Re: VBA code to list all products from each customer in one note

    Seems I've seen this problem once before... anyway, try this...
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    dangelor : Thanks for response. The code works, however, I don't want to delete any rows from data. If there is multiple matches then result should list all results one below the other and copy it. Basically, I need to upload the copied values in SAP against one particular Customer name(I can do the SAP part, I just need the looping in VBA). the copied results should be one below other, something like for "Claire Gute" it should show

    FUR-BO-10001798
    FUR-CH-10000454

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    See if this is how you wanted.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, Thank you so much. This is exactly what I needed. Just for my learning purpose, do you mind commenting on steps you followed. Thanks a ton in advance.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Please Login or Register  to view this content.
    HTH

  8. #8
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Thanks again.

  9. #9
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Hey everyone, I need to modify this program to hold 3 dimensions in array. For example, for each customer name, it should give corresponding data for category and Product ID.

    As earlier, If there is multiple row for one customer then It should display customer name and Category(if there are 2 category, it should split to next line) only once but matching prodcut ID should be listed in one line. for exampleCapture.PNG

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Change to
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, this code works for three columns but it is not diving the category into 2 parts for customer who has more than one category. For example "Tracy Blumstein" has Furniture and office supplies. When I run macro it just shows furniture in category column.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Quote Originally Posted by Jimmy1709 View Post
    It should display customer name and Category(if there are 2 category, it should split to next line) only once but matching prodcut ID should be listed in one line. for exampleAttachment 627896
    I just changed the code according to your picture.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, sorry to bother you so much. But, when there are multiple criteria, sheet is keeping all of them but in the same line. However, I need them in different line as shown in picture. Furniture and office supplies should be on 2 lines not in a single line. I owe you for this one bro.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Do you mean?
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Yes, this is exactly what I wanted. Thank you so much.

  16. #16
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, sorry but need one final help. Can you please comment on the code where it adds new sheet ? and also, help me code to delete the newly created sheet. If I want to newly created sheet to upload in SAP and then delete after upload in SAP complete. Whats the change I need to do in code ?

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Thanks a lot Jindon.

  19. #19
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, I need one more small adjustment to the code. I tried doing it myself since last 2 days but no luck. Instead of creating new sheet every time, I need the array values to be pasted on Pre formatted sheet with headings( Sheet name be "Upload_data"). In this case, pre formatted headings would Cutomer ID, Category and Product ID. The values from array(skipping array headings) should be copied from 2nd row onwards, when we run the Macro. Can this be done ?

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Change to
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Hey Jindon, This is copying to a existing sheet but the values of product Id are messed up. It is getting random results. They are not sorted as per condition.

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    They are not sorted as per condition.
    What is this?

    what condition???

  23. #23
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Attachment 628541Attachment 628540

    For example, customer Tracy Blumstein, the products and category is not matching with whats in Raw data. See the attached photos. One for actual data(pivot table) and other one VBA output

  24. #24
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    in the image where heading -customer name is misspelled is VBA output.

  25. #25
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, I fixed that issue. Its working now. But new problem I have is its deleting the content from upload_data sheet before running. I dont want this to clear content, however, if I run the macro twice, it should keep the first run results and add any news rows I have added to raw sheet. The code that worked for proper sorting is below

    Please Login or Register  to view this content.

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Proper change should be
    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, this code works. But, when I run macro twice, instead of adding just newly added rows it adds all rows again and duplicating the values.

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    I don't understand what you want.

    Upload a workbook with before/after.

  29. #29
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    In workbook, consider sheet1 is my data in the morning. I ran Macro on that to get results. In afternoon I added data from sheet2 to sheet1 and ran macro on sheet 1 again. In this case, new data and existing data should be merged/combined in output "upload_data" worksheet(note it already has data from morning when I ran same macro again). Hope this is more clear now.
    Attached Files Attached Files
    Last edited by Jimmy1709; 06-16-2019 at 10:14 PM.

  30. #30
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    No one can understand what you are trying to do unless a sample workbook.

    How are you adding a new sheet, or how do you want the code to determine which sheet to be processed?

  31. #31
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Code should process on the same sheet. People will be adding more data to it the same sheet throughout day(manually or copy paste from any other sheet to sheet1) and run the same macro multiple times in a day. When someone see the results "output_data" sheet anytime during the day it should have up to date information but no duplicates.

    Main idea here is, if I upload my results "Upload_data" in morning to SAP. then add more data by afternoon, it should skip the ones uploaded to SAP and only upload new rows from "upload_data" sheet.
    Last edited by Jimmy1709; 06-16-2019 at 10:53 PM.

  32. #32
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Still not clear.

    1) Do you want to process data from the scratch every time you add the new data?
    or
    2) Newly added data should be treated as a different set of data?

    If case 2), you need to isolate the new data from the old data.

  33. #33
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Newly added data should be treated as new data(but this should all happen in same sheet - as i will be using data from only this sheet to upload to SAP). I just edited my previous response also. The purpose is all about avoiding duplicate entries in SAP.

  34. #34
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Then how you adding the new data?
    Is it possible to add a blank row(s) when you add new set of data?

    e.g.

    Old data
    (blank row(s))
    New data

  35. #35
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Just to make it simple to understand, may be when macro runs it should add comment "Yes" in column D of all data rows in "upload_data" worksheet.

  36. #36
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    When uploading to SAP, I can use the column "D" value as variable for loop. If there is already "Yes" I will skip it. If there is no "yes" then i will script SAP to upload only that data to SAP.

  37. #37
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    If blank row(s) create lot of complexity in code then we can skip that for now. just consider data as continuous. If not considering blank row(s) in main data would be helpful to have robust Macro.

  38. #38
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    What you think is completely wrong, it makes easy to modify the code.

  39. #39
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Oh OK, I am very new to programming and learning everyday from experts like you and YouTube videos. but, adding a comment "yes" in column D would be necessary. It makes looping SAP script easier. Can that be done ? along with considering the blank rows.

  40. #40
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Col.C Yes, no blank row.
    Please Login or Register  to view this content.

  41. #41
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, no worries about blank row. but, this code doesnt work even for outputting the results as our earlier code. It skips many data rows. Also, there is no "yes" in column D

  42. #42
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Just noticed, its adding "yes" in data input tab. I need that in results sheet "upload_data"

  43. #43
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    run the code once, it changes col.d to YES
    copy data in sheet2 and add it to the bottom, and run again.
    Attached Files Attached Files

  44. #44
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Quote Originally Posted by Jimmy1709 View Post
    Just noticed, its adding "yes" in data input tab. I need that in results sheet "upload_data"
    What for?

    How do you find old data and new data in Sheet1???

  45. #45
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    You need to upload a workbook before after for both data sheet and the result, otherwise just wasting time.

  46. #46
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Jindon, I am sorry I am confusing you more I feel. I need the "Yes" indicator to upload only new output to SAP. I only use "output_data" sheet to upload to SAP. All other sheets are not much importance. I just need data to be summarized in "output_data" sheet and add "yes" indicator in output sheet.

    Just to keep it short, your solution on comment#26 is perfect as I needed. I just need to add "Yes" in column D of the "output_data" sheet when macro finish running. Can that be done ?
    Last edited by Jimmy1709; 06-16-2019 at 11:59 PM.

  47. #47
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Quote Originally Posted by jindon View Post
    What for?

    How do you find old data and new data in Sheet1???
    I need not differentiate old or new data in raw data. I need that to differentiate in output sheet. Hence the requirement of "yes" in column D of output sheet. sorry for making all this confusion.

  48. #48
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Quote Originally Posted by jindon View Post
    You need to upload a workbook before after for both data sheet and the result, otherwise just wasting time.
    Upload just a small amount of data sets, no need more than 10 rows, clearly showing before/after.

  49. #49
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code to list all products from each customer in one note

    Quote Originally Posted by jindon View Post
    Upload just a small amount of data sets, no need more than 10 rows, clearly showing before/after.
    Here is the attached sheet.
    Attached Files Attached Files

  50. #50
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Then what should happen after you add new data in sheet1?

  51. #51
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53
    Quote Originally Posted by jindon View Post
    Then what should happen after you add new data in sheet1?
    That should just copy below this data, I don’t want to delete any data. I wanted to create loop to make it easier but that’s causing lot of confusions. I will be able to get that done myself while uploading to SAP.

  52. #52
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    I'm confusing more.

    Are you adding New data below the Old data in Sheet1 at all?

  53. #53
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53
    Quote Originally Posted by jindon View Post
    I'm confusing more.

    Are you adding New data below the Old data in Sheet1 at all?
    Answer is yes, but I think if you give me solution to this now. I can figure that out myself. For now, if macro does Befpre and after as attached sheet that’s sufficient.

  54. #54
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,716

    Re: VBA code to list all products from each customer in one note

    Add one line in bold.
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  55. #55
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53
    Quote Originally Posted by jindon View Post
    Add one line in bold.
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Wow, was that such simple 🙈 I took a hell amount of your time for it. I really appreciate your patience and kindness Jindon. Thanks again for everything. Just to solve your curiosity, I just sent you pm explaining my overall problem which I wanted to attain solution for, I guess I am half way through it: I can close the loop 😊

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 02-26-2018, 01:01 PM
  2. Replies: 3
    Last Post: 11-17-2017, 09:09 PM
  3. Distinct products per customer
    By oteixeira in forum Excel General
    Replies: 5
    Last Post: 05-09-2017, 09:53 AM
  4. [SOLVED] Products for specific customer should appear in text boxes when we choose that customer.
    By MariaPap in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-21-2014, 05:22 AM
  5. Finding out how many products a customer permanently stocks.
    By Paxman71 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2013, 10:15 AM
  6. Top 3 sold products and qyty by customer from list
    By e602043 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-08-2013, 11:01 AM
  7. Searching and displaying multiple products per customer
    By idemdito in forum Excel General
    Replies: 1
    Last Post: 09-13-2011, 08:38 AM

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