+ Reply to Thread
Results 1 to 32 of 32

Populate Sheet from Database

  1. #1
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Populate Sheet from Database

    Hi
    I have data for actual sales that comes from a Sales DB.

    I want to be able to populate a sheet with data from the DB and allow the Sales Manager to enter the forecast for each stock item. The totals would be created too.

    Each Division has a different list of Stock Items. The Sheet would have a field in which the Sales Manager would enter their Division Code and when prompted then the Sheet would populate from the DB. They would then enter their forecast and save the sheet.

    I am thinking this might involve VBA but what are possible non-Macro approaches. I can use PowerBI if necessary.

    Thank you
    Attached Files Attached Files
    Last edited by AllisterB; 01-14-2021 at 05:33 PM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Populate Sheet from Database

    If could add the forecast in the last column of the data you could use Pivot Table and Calculated Field, see file attached.
    Else how is your data layout: Which sheet recieves the data, which one is displaying what ?
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Thanks PCI

    The blue table in my workbook is data coming from an accounting system. the Sheet A and Sheet B blelo the Blue Tableis what I want to end up with.

    What I am trying to do is produce a Sheet (eg Sheet A and Sheet B) where the Manger can manually key in into the cells in the Forecast and Columns ... Once this manual entry has been made then I can use Pivot Tables, PowerBI etc.

    Thanks again

    Allister

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

    Re: Populate Sheet from Database

    I'm not sure about the figures in B.
    This is how I read your problem.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Populate Sheet from Database

    Please try Power Query

    branch A can be changed

    Please Login or Register  to view this content.

    column Forecast, Difference, Comment are manually added.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Hi Jindon

    Thank You for your effort in providing me with a potential solution.

    How would the following be best treated

    1. tour solution does a great job at setting up the initial structure for each Branch. My comment relates to what happens after the initial creation of a Sheet. Can VBA Test if there is a Sheet for the Branch? - if there is a sheet for the branch then test if the Account exists - if the account does not exist then insert a row in the correct sequence for the account. If the Account does exist then do nothing. If there is not a Sheet for the Branch then create one as per your code.

    2. If Table 1 in my example is a Power Query Output Table - What I want to achieve is for the Sheets A and B to be dynamic - so as values in the Table changes so do the values in Column G of sheets A and B.

    Thank You

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

    Re: Populate Sheet from Database

    1)
    - Does "Account" mean "Name"?
    Let's take A sheet
    it has
    Stock Code Item Name Value
    1300 Pants Clothing 100
    1300 Pants Clothing 120
    1300 Pants Clothing 300
    When the main data is refreshed, how do you determine the one to update the "Value"?

  8. #8
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305
    Value should read stock code
    Last edited by AliGW; 01-07-2021 at 02:38 AM. Reason: PLEASE don't quote unnecessarily!

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

    Re: Populate Sheet from Database

    Suppose, 1300 is now have 1 row after the refresh of the power query in Sheet1.
    How should it be done?

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Populate Sheet from Database

    @AllisterB - please don't ignore contributors to your thread - acknowledge all solutions offered, even if they don't meet your requirements. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: Populate Sheet from Database

    That happens everywhere in this forum...

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Populate Sheet from Database

    Doesn't mean it should. I will always try to pick members up on it when I see it happen.

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

    Re: Populate Sheet from Database

    So, you should work harder than ever to find such threads from now.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Populate Sheet from Database

    You are taking this OT, but to be clear: I don't go hunting for discourtesy, but I will tackle it when I come across it. Let's get back to the task in hand now, please.

  15. #15
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305
    Quote Originally Posted by jindon View Post
    Suppose, 1300 is now have 1 row after the refresh of the power query in Sheet1.
    How should it be done?

    On sheetA there will be one row for 1300 with the total of all rows in table 1 for Branch A stock code 1300.

    I trust this answers your question.

    Allister

  16. #16
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305
    Quote Originally Posted by AliGW View Post
    @AllisterB - please don't ignore contributors to your thread - acknowledge all solutions offered, even if they don't meet your requirements. Thanks.
    Do I need to mark a reply as a solution if it doesnt work or doesn't give me a solution I can use or is not the best solution.?

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

    Re: Populate Sheet from Database

    If they are unique, no problem, but your sample had duplicate rows with different values in each worksheet as the result and so I coded as such.
    If your uploaded sample workbook is not correct, I need to see the correct result.
    Otherwise I can not write a code without the clear logic.

  18. #18
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305
    Quote Originally Posted by jindon View Post
    If they are unique, no problem, but your sample had duplicate rows with different values in each worksheet as the result and so I coded as such.
    If your uploaded sample workbook is not correct, I need to see the correct result.
    Otherwise I can not write a code without the clear logic.
    Tomorrow I will send better sample to clarify.

    Thank You

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Populate Sheet from Database

    Quote Originally Posted by AllisterB View Post
    Do I need to mark a reply as a solution if it doesnt work or doesn't give me a solution I can use or is not the best solution.?
    No, but if somebody has gone to the trouble of offering you help for free and in their own free time, the least you can do is say 'thanks'! You have completely ignored Bo-Ry's offering in post #5 - do him the courtesy of an acknowledgement, please.

  20. #20
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305
    Quote Originally Posted by Bo_Ry View Post
    Please try Power Query

    branch A can be changed

    Please Login or Register  to view this content.

    column Forecast, Difference, Comment are manually added.
    Thank you... I think I may have have an alternate approach for solution do all hood

  21. #21
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Quote Originally Posted by AllisterB View Post
    Tomorrow I will send better sample to clarify.

    Thank You
    I have attached an updated file that I trust makes things clearer. Table 1 now only includes one instance for each Stock Code. This post replaces Post #6.

    From your earlier solution it appears that VBA can produce an initial output that a manager can then use to manually input for each row values and/or formula into the Forecast and Comment cells.

    When Table 1 changes, I want to be able to update the output while still retaining any contents of the Forecast and Comments cells. For clarity: if there is anything in the Forecast and/or Comment cells on a row then that needs to be retained intact after the update has occurred. If the contents of the Forecast and/or Comment cells was a formula, then this formula needs to work as it did before.

    Also please note that It is okay for a stock code that no longer exists in Table 1 to now not show in the updated output, so long as there was previously no contents in the Forecast and/or Comment fields of the output.

    My Question is how can this be done?

    Thank You

    Allister
    Attached Files Attached Files

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

    Re: Populate Sheet from Database

    Didn't test the code hard, so may have bugs...
    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Hi Jindon

    Thank you for your efforts in modifying the macro.
    When I ran it I got an automation error on the row Set dic(a(i, 1)) = CreateObject("System.Collections.SortedList")
    Kind Regards

    Allister

  24. #24
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Populate Sheet from Database

    See

    https://social.msdn.microsoft.com/Fo...forum=exceldev

    and download Microsoft .net framework 3.5

  25. #25
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Hi Jindon

    Thank you

    I have managed to get this to work - I'll test it tomorrow

    Allister

  26. #26
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Again thank you Jindon for your solution

    I have noticed several things that I think are related to each other.

    • When the macro runs it does update the output for any change in the Stock Code. However, if there is a change in the Branch then when the macro runs then that Stock Code is output to the new Branch Tab but it still
    appears on the sheet for the Branch Value.

    • If the Description of an Item (or for Name) Changes the output of the macro does not pick up the new description.

    • If a record in Table 1 is deleted, then when the macro is run the record still appears in the output.

    It seems to me that the macro is retaining data that is now not in Table 1.

    Is there a fix for this?
    Attached Files Attached Files

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

    Re: Populate Sheet from Database

    Leave "test" procedure as it is and replace other 2 private sub procedures with the folloiwng.
    Please Login or Register  to view this content.

  28. #28
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Hi Jindon

    the macro runs the first time. But if I immediately run it again (no changes to Table1) I get a 1004 error No cells were found

    The Debug highlights on row

    r.CurrentRegion.Columns("g").SpecialCells(-4123).EntireRow.Delete in eth SubWS code.

    Regards

    Allsietr

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

    Re: Populate Sheet from Database

    Can not replicate such error, so no idea.

  30. #30
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    Hi Jindon

    Could you run the attached - this will tell me if it is something with my system or not - thank you

    Allister
    Attached Files Attached Files

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

    Re: Populate Sheet from Database

    OK, error on 2nd time...

    Can you delete A & B sheet first and run the code, because the layouts are slightly different from the first code.
    Last edited by jindon; 01-14-2021 at 12:21 AM.

  32. #32
    Forum Contributor
    Join Date
    07-10-2020
    Location
    New Zealand
    MS-Off Ver
    365 personal
    Posts
    305

    Re: Populate Sheet from Database

    This worked thanks.

    I've done some testing and it works largely as I need it too - I'll press on with it now and see what I can do - thanks again for your efforts

+ 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. Populate a Listbox with external database
    By nicola_1988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2020, 11:16 AM
  2. Auto populate quote sheet with values from a database
    By Matcho09 in forum Excel General
    Replies: 1
    Last Post: 07-09-2019, 09:02 AM
  3. [SOLVED] How to populate a table from a database
    By renzo.renzetti in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-25-2018, 09:15 AM
  4. Populate matrix using database information?
    By starnz in forum Excel General
    Replies: 3
    Last Post: 07-30-2012, 08:47 PM
  5. Populate invoice from database sheet (Attached)
    By Mayweed in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-24-2010, 08:55 AM
  6. Auto populate the selection from the database
    By justinng in forum Excel General
    Replies: 5
    Last Post: 01-15-2010, 01:59 PM
  7. Replies: 0
    Last Post: 02-16-2007, 09:12 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