Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #12  
Old 03-08-2024, 11:25 AM
gmaxey gmaxey is offline Help! - multiselect userform listbox with dependent drop down Windows 10 Help! - multiselect userform listbox with dependent drop down Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

If this stuff was easy, anyone could do it. Here is something for you to contemplate:

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim arrFordOptions() As String
Dim arrToyotaOptions() As String
Dim arrNissanOptions() As String
Dim oColOptions As New Collection
Dim lngIndex As Long
Dim bFord As Boolean, bToy As Boolean, bNis As Boolean
  
  arrFordOptions() = Split("Auto Pilot|Tires|mirrors", "|")
  arrToyotaOptions() = Split("Warp Drive|Tires|headlights", "|")
  arrNissanOptions() = Split("Rear facing seat|Tires|taillights", "|")
  'Let's assume the user selects Ford and Toyota so:
  bFord = True: bToy = True
  'Many times with VBA, errors can be your friend:
  On Error Resume Next
  If bFord Then
    For lngIndex = 0 To UBound(arrFordOptions)
      oColOptions.Add arrFordOptions(lngIndex), arrFordOptions(lngIndex)
    Next
  End If
  If bToy Then
    'One of the Toyota options "tires" duplicates a Ford option.
    For lngIndex = 0 To UBound(arrToyotaOptions)
      'When the tires option is hit the error is thrown because each item in the collection must have a unique key.
      oColOptions.Add arrToyotaOptions(lngIndex), arrToyotaOptions(lngIndex)
    Next
  End If
  If bNis Then
    For lngIndex = 0 To UBound(arrNissanOptions)
      oColOptions.Add arrNissanOptions(lngIndex), arrNissanOptions(lngIndex)
    Next
  End If
  'Populate your dependent list with the collection items
  For lngIndex = 1 To oColOptions.Count
    Debug.Print oColOptions.Item(lngIndex)
  Next lngIndex
    
lbl_Exit:
  Exit Sub
  
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Userform multiselect listbox populate trevorc Excel Programming 1 12-03-2018 02:49 PM
Multiselect listbox - custom outlook form A_Balt Outlook 0 07-19-2018 09:36 AM
Help! - multiselect userform listbox with dependent drop down Moving Selected Items from a Multiselect Listbox on a userform to a bookmark in Word marksm33 Word VBA 3 01-15-2015 07:55 PM
Help! - multiselect userform listbox with dependent drop down This is a Userform LIstbox queston: A variable does not set to the value of a listbox CatMan Excel 1 08-08-2014 09:41 AM
Data from Excel to Listbox multiselect to Word marksm33 Word VBA 2 02-18-2014 08:30 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:23 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft