Results 1 to 6 of 6

How to simplify Multiple ComboBox Change Event code

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    How to simplify Multiple ComboBox Change Event code

    Hi All Expert,

    I have one comboBox depend on another 4 comboBoxes. It would be short to create change event

    Private Sub ComboBox27_Change()
    
        If Me.ComboBox27.Value <> Empty Then
             For i = 28 To 31
                With Me.Controls("ComboBox" & i)
                       .Clear
                       .Enabled = False
                End With
            Next i
    
        Else
            For i = 28 To 31
                With Me.Controls("ComboBox" & i)
                       .Enabled = True
                       .Clear
                       .List = wsData.Range("AA2:AA11").Value
                End With
            Next i
        End If
    End Sub


    However, each of 4 ComboBoxes also depend on a single comboBox as described above. Thus, I have to create 4 times change event to ensure it working fine. Is there any method to create only one change event instead of 4 as described below?

    Private Sub ComboBox28_Change()
    Private Sub ComboBox29_Change()
    Private Sub ComboBox30_Change()
    Private Sub ComboBox31_Change()
    
    
     '\\The same code use for all change event
       If Me.ComboBox28.Value <> Empty Or _
          Me.ComboBox29.Value <> Empty Or _
          Me.ComboBox30.Value <> Empty Or _
          Me.ComboBox31.Value <> Empty Then
          
            With Me.ComboBox27
                   .Clear
                   .Enabled = False
            End With
       Else
            With Me.ComboBox27
                   .Enabled = True
                   .Clear
                   .List = wsData.Range("AA2:AA11").Value
            End With
       End If
    Last edited by Faridwahidi; 10-21-2016 at 11:42 AM.
    1. Thank those who have helped you by clicking the Star * below the post.
    2. Please mark your post [SOLVED] if it has been answered satisfactorily.

    Sincerely,
    Farid

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Combobox change event
    By buhwheet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2015, 10:39 AM
  2. Same WorkSheet Change Event Code Across Multiple Sheets Help
    By jaylove in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-03-2014, 06:01 PM
  3. Fix change event code to add todays date when data is added to multiple cells in column
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 12-21-2013, 06:40 PM
  4. VBA Code: Change event, multiple if's for a range
    By dhopman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2012, 11:27 AM
  5. Change event for comboBox
    By cmpcwil2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2006, 10:01 AM
  6. Combobox change event only by UI
    By Excelerate-nl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2006, 11:10 AM
  7. [SOLVED] MsgBox in Enter event causes combobox not to run Change event
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2006, 10:55 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