title: How to set dropdown selection from code in Excel (VBA)
body: <p>I am trying to make a filter for an Excel table. I have 2 dropdown boxes with the items lists dynamically added in a macro that's called when the table is refreshed.</p>
  
  <pre><code>Set selectBook = Worksheets("Report").DropDowns("DropDownBook")
  selectBook.RemoveAllItems
  
  For Each b In books
          selectBook.AddItem (b)
  Next
  </code></pre>
  
  <p>Where "books" is an array with the new values. Code for the other dropdown with "authors" is similar.
  After running this macro, there are no initial selections displayed. I have attached a macro to the dropdownchange event, that reads the selections in both dropdowns</p>
  
  <pre><code>Set books = Worksheets("Report").DropDowns("DropDownBook")
  bookSelect = books.List(books.ListIndex)
  </code></pre>
  
  <p>and does the necessary filtering. Problem is, if I select an author, the macro will break in the second line of code given above with</p>
  
  <pre><code>Run time error '1004':
  Unable to get the List property of the DropDown class
  </code></pre>
  
  <p>and if i select a book, it will do the same for authors. I guess this happens because there isn't an initial selection in the boxes, but I can't seem to find a way how to make one in code. I have tried</p>
  
  <pre><code>selectBook.ListIndex = 0, selectBook.Value=0 etc.
  </code></pre>
  
  <p>, but nothing has worked. Am I missing something obvious? Any help will be greatly appreciated.</p>