+ Reply to Thread
Results 1 to 5 of 5

Broken drop-down list due to its contents being changed with a macro

  1. #1
    Registered User
    Join Date
    10-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    78

    Broken drop-down list due to its contents being changed with a macro

    I have set up drop-down lists on the "Hardware" sheet which look at my stock tables on the "Stock Sorting" sheet and makes the table corresponding to the table the drop down menu is housed in their range to give the user an option of which product they want to select.

    I currently have two stock systems: the first stock system I have is on the "Stock Table" sheet which is one table that holds all of the stock I have. My second stock system is on the "Stock Sorting" sheet which looks at the first stock table on the "Stock Table" sheet and separates the stock into tables for each product type. For example the stock table on the "Stock Table" sheet will hold all of the motherboards, CPUs, GPUs ETC.... the second stock system on the "Stock Sorting" sheet looks at first table and pulls out all of the motherboards and puts them in their own table, all of the CPUs and puts them in their own table ETC...

    The VBA code I am using to update the second stock system every time stock is added to the first seems to ruin the drop-down lists I am using. The code looks at the first table on the "Stock Table" sheet and for the motherboard table on the "Stock Sorting" sheet it copies all of the motherboards and pastes them over the contents of the the table so if motherboards have been taken away from the main table the motherboard table will loose those motherboards and if motherboards have been added to the first table the motherboard table will gain those motherboards. When this is done the drop-down lists which are using the tables on the "Stock Sorting" sheet as their range are broken and when looking at what their range is set at this error is displayed "='Stock Sorting'!#REF!". The drop-down lists int the hardware section of the "hardware" sheet are meant to have this range when not broken "='Stock Sorting'!$C$5:$C$1000". The code below is triggered every time the user form to add stock is used. Is there anyway from stopping the drop-down menus range from being broken or code that updates the range when the code that breaks them is used?

    Here is the workbook and code to allow you to help me and understand the problem:

    Drop-Down Lists.xlsm

    Please Login or Register  to view this content.
    Last edited by mdovey; 04-13-2014 at 01:21 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Broken drop-down list due to its contents being changed with a macro

    Hi,

    I don't have access to Excel just at the moment but are your drop down lists using defined range names? Maybe in deleting A4:A1000000 you are deleting a range name.

    Incidentally you seem to have uploaded a .xlsx file rather than a .xlsm one.

    One other point. Since your large macro contains subsections which are essentially the same apart from a different column ref it would be more efficient to create an array of these column letters and then have a loop which loops 20 times and use the loop counter to pick the column ref from the array each time.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    78

    Re: Broken drop-down list due to its contents being changed with a macro

    Hello,
    No the drop down lists are using code such as "='Stock Sorting'!$C$5:$C$1000" so they are referring to the cells. Im not sure if using the code I have posted above deletes the cells completly for a breif second which is causing the range to be broken as it can no longer find the cells and doesnt automaticly update the link when the cells come back. Is there different code I could be using such as a Clear command rather than Delete? This could fix the problem of the range being broken. Maybe even by using named ranges instead that might fix the problem?

    Thank you for pointing out my attachment I managed to upload the wrong version. I have fixed it now and the correct workbook is uploaded.

    The array probably would be much more efficient but I am fairly new to VBA so am only good with basic coding and having people suggest code to use. An array does sound like a much cleaner and more efficient way but for now I guess its not my priority so I am happy to deal with it until I get problems such as this one out of the way.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Broken drop-down list due to its contents being changed with a macro

    Hi,

    As I thought, it's because you are deleting row 4:1000000 which includes within it your validation drop down definitions. Instead of deleting rows use

    Please Login or Register  to view this content.
    As I say the current code could be much simplified so when you are ready repost and no doubt someone will sort it out.

  5. #5
    Registered User
    Join Date
    10-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    78

    Re: Broken drop-down list due to its contents being changed with a macro

    Thank you very much this has helped out a lot. Thanks you for the extra advise as well, once all of the main parts are ironed out I will come back and get someone to help out with the array.

+ 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. Using IF to check the cell contents from a drop-down list
    By helen269 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-23-2012, 07:39 AM
  2. Replies: 5
    Last Post: 03-26-2012, 11:50 PM
  3. Replies: 5
    Last Post: 03-01-2012, 01:56 PM
  4. [SOLVED] Need a conditional drop-down list (list contents)
    By S&F Tie Guy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2006, 10:25 AM
  5. Replies: 5
    Last Post: 06-19-2005, 08:05 PM

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