+ Reply to Thread
Results 1 to 9 of 9

Code Simplification

  1. #1
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Code Simplification

    Hello experts and users,

    I wrote a code which was working fine but as the data changed, the procedure became rather cumbersome and I realised that it's not the most efficient way of writing it and I could easily have loads of mistakes in the process. So, I'm begging for your kindness and expertise to direct me to a way I could rewrite the following code in a more efficient and simplified way.

    This is a dependent drop down list based on the selection made within the first field (ComboBox1) in this case.

    I was thinking for probably creating a column for each case but unsure where to go from there.

    Your help is much appreciated.

    Best wishes,

    Please Login or Register  to view this content.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by rakotonirinas; 09-03-2021 at 07:15 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: Code Simplification

    Please see the yellow banner at the top of the page.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Code Simplification

    Attached on the original post is a slim down version of the workbook. Thank you

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: Code Simplification

    This is a little bit shorter but using the same structure:

    Please Login or Register  to view this content.
    The only other way I can think of is to have a table on a "Control" sheet somewhere that has a matrix of Service Type and Suppliers. Depending on the index for ComboBox1, you could loop through the suppliers for the service type.

  5. #5
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Code Simplification

    Thanks for this @TMS. I created the components sheet for that purpose but I wasn't sure how to formulate the code from there. Still learning.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Code Simplification

    You have the Lists available in Components Sheet so why not just give each list the correct Header referencing the Combobox drop down...
    This will allow for a more simplistic approach...
    This will give you an idea...i changed your sheets for testing...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 09-03-2021 at 08:27 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  7. #7
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Code Simplification

    Hello,
    Thank you for your contribution. This is definitely a good work around. Thank you.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,304

    Re: Code Simplification

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: Code Simplification

    Alternative using proper tables - no need for separate component list - first combobox is populated from the table headers.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

+ 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. VBA Simplification
    By Raj ASRP in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-24-2020, 11:40 PM
  2. [SOLVED] Simplification of code for Chart Series control
    By mattydboom1 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-23-2020, 10:40 AM
  3. Autofilter loop + copy paste?
    By dunnobe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2019, 04:20 AM
  4. [SOLVED] Code simplification (format and conditional formatting)
    By dunnobe in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2018, 10:19 AM
  5. [SOLVED] Simplification for regex code to replace numbers in a comma delimited string
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2018, 06:30 AM
  6. Simplification of macro code
    By PvanS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2009, 10:42 AM
  7. Lock cells based on value of other cells - code simplification query
    By glenin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-07-2009, 03:11 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