+ Reply to Thread
Results 1 to 20 of 20

Setting list index of drop down list, or clearing them ?

  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Setting list index of drop down list, or clearing them ?

    Hi,

    let's say I have created a validation list in cell A1, and list is called "My list". There are numbers from 1 to 9 in that list, and first cell in range of list is blank - so index of that cell would be 0.

    Then I select something else than first - blank - item from list (numbers).

    How can I, with VBA, change drop-down list index back to first (blank) cell ?

    Tried with this, not working :
    Please Login or Register  to view this content.

    Thanks for help !!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Setting list index of drop down list, or clearing them ?

    Is "My list" a named range of cells? If yes, the name wouldn't have a space in it. Otherwise, I'm not sure what you're asking.

    You could reset A1 to blank.
    Cells(1, 1).Value = ""
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    Yes, "My list" is a named range of cells. It is only example, you can name It My_List.

    I'm trying to get all my drop-down cells blank, but need that in a range where there are other cells which have formulas in It, and formulas must be intact.

    So
    Cells(1, 1).Value = ""
    is not an option, because in range every cells would be blank.


    Also, I forgot to mention - in range where I need that ("F18:BN412"), I have multiple drop-downs with different ranged names.
    Last edited by Lukael; 07-30-2014 at 08:22 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Setting list index of drop down list, or clearing them ?

    That doesn't make any sense to me. In order to reset any DV cells you must be able to identify them as DV cells, at which point you can simply set the value as AlphaFrog showed.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Setting list index of drop down list, or clearing them ?

    Hi Lukael,
    try semicolon
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    Hi Nilem,

    I tried, same result as in post#1

  7. #7
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    In order to reset any DV cells you must be able to identify them as DV cells
    Ok, I understand you, but can this be done ?

    I know It sounds a little strange question, but I have huge table where there needs to be cleared all cells after running macro. And this range contains drop-down Shapes, DV cells and cells with formulas, which mustn't be deleted.

    See this sample, open It and just hit the RUN button. After creating all months be focused on 1st day of months (excluding December which works???), you'll notice that It clears Drop-down shapes, leave formula cells intact but not values in DV cells.

    The code that should clear cells is in Clear_cells macro....
    Attached Files Attached Files
    Last edited by Lukael; 07-30-2014 at 08:53 AM.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Setting list index of drop down list, or clearing them ?

    You can use:
    Please Login or Register  to view this content.
    to clear the DV cells.

  9. #9
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Setting list index of drop down list, or clearing them ?

    "It clears Drop-down shapes, leave formula cells intact but not values in DV cells."

    maybe so
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    Have tried, but not working.

    Paste this code in sample and you'll see. Sample code doesn't properly clear Drop-down Shapes, this one does.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Setting list index of drop down list, or clearing them ?

    I think the confusion has been because your terminology is incorrect. You are using Form-type dropdown lists and not Data Validation lists.

    nilem suggestion should work.

  12. #12
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    Tried that too, still no succes :

    Please Login or Register  to view this content.
    I also called the code separately right under the code for Drop-Down shapes, same result.

  13. #13
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    I think the confusion has been because your terminology is incorrect. You are using Forms-type dropdown lists and not Data Validation lists.
    I wasn't aware of that, I thought these are Validation lists since you need to asiggn them named range in Data>Validation>Settings>List. I'll read more about this !

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Setting list index of drop down list, or clearing them ?

    The code I posted clears data validation cells, not cells linked to Forms controls. (You have both)

  15. #15
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    Ok, now I'm really confused about this Data validation term. I pasted your code in this sample, but I still don't get 0 index in DV cell. I placed button for your code.

    The code I posted clears data validation cells, not cells linked to Forms controls. (You have both)
    You're right ! Except that Form control has a list, and It's selected Item is inserted into cells under, which have also drop-down list in case User selects other values for Start/End times. Form control + these cells needs to be blank.
    Attached Files Attached Files

  16. #16
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Setting list index of drop down list, or clearing them ?

    Quote Originally Posted by Lukael View Post
    You're right ! Except that Form control has a list, and It's selected Item is inserted into cells under, which have also drop-down list in case User selects other values for Start/End times.
    Not sure what you mean. In point of fact, since your DV cells only contain literal values, your Specialcells line that clears constants should clear those DV cells too, if they are populated.

  17. #17
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    Yes, I know that, and I'm checking all the code If something prevents that clearing specialcells to be done, but can't figure It out. It worked 14 days ago, now It doesn't.

  18. #18
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?

    I figured It out !

    Looks like there is some flaw in this lines of code :

    Please Login or Register  to view this content.
    I deleted It and tried only with :

    Please Login or Register  to view this content.
    Now It works, but executing of code is a little bit slower, so I reckon that Clear_cells macro has some errors. Is It better to separate all other commands in the macro and just call them within ?

    Also, still can't figure why that lines of code would cause problem. All It does differently is how It determines where to clear special cells

  19. #19
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Setting list index of drop down list, or clearing them ?

    I missed that - it should be:
    Please Login or Register  to view this content.
    Note the dots before Cells

  20. #20
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Setting list index of drop down list, or clearing them ?



    WHAT A STUPID mistake, wouldn't notice that EVER ! Thanks a lot !!! Now It works !!!

+ 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. How to get index of selected item in drop down list?
    By nleahcim in forum Excel General
    Replies: 3
    Last Post: 08-08-2011, 02:08 PM
  2. [SOLVED] clearing blanks in drop-down list
    By Richard Walker in forum Excel General
    Replies: 1
    Last Post: 05-22-2006, 07:00 PM
  3. [SOLVED] Setting default values in a drop down list in excel?
    By Dave in forum Excel General
    Replies: 2
    Last Post: 05-18-2006, 02:40 AM
  4. [SOLVED] Clearing the Values in a Drop - Down List
    By Sagu in forum Excel General
    Replies: 4
    Last Post: 03-30-2006, 10:35 PM
  5. [SOLVED] Clearing the Values in a Drop - Down List
    By Sagu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2006, 07:15 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