Results 1 to 5 of 5

Skip hidden control when looping all controls on a userform

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-19-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Office365
    Posts
    276

    Skip hidden control when looping all controls on a userform

    Hello, I have this function that stopped working when I added the line "If ctrl.Visible = True Then".

    the function checks all controls on a userform to see if it is filled. I have a bunch of them invisible depending on user selection in another combobox. I need the function to ignore those hidden ones because they won't be filled.

    can someone please help me fix it? Thanks in advance!

    Private Function EverythingFilledIn() As Boolean
    
        Dim AnythingMissing As Boolean
        EverythingFilledIn = True
        
        Dim ctl As MSForms.Control
        
        For Each ctl In Controls
         If ctrl.Visible = True Then
            If TypeOf ctl Is MSForms.TextBox Or TypeOf ctl Is MSForms.ComboBox Then
                If ctl.Value = "" Then
                  ctl.BackColor = rgbPink
    
                  If Not AnythingMissing Then ctl.SetFocus
                  AnythingMissing = True
                  
                  EverythingFilledIn = False
                End If
            End If
            End If
        Next ctl
        
     
    End Function
    Last edited by lynnsong986; 10-16-2020 at 01:41 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Cleaner code for looping through userform controls (beginner)
    By melpa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-20-2019, 08:07 AM
  2. [SOLVED] Find Userform controls based on Control Name
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2017, 02:33 PM
  3. [SOLVED] Looping Through Userform Controls
    By omagoodness in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-23-2016, 02:45 PM
  4. Looping through controls on a worksheet to set control icons
    By insomniac53 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2015, 11:04 AM
  5. Replies: 5
    Last Post: 02-27-2013, 12:04 PM
  6. [SOLVED] Looping through controls on a MultiPage control
    By Paul Martin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2005, 01:06 AM
  7. [SOLVED] Problem with looping through userform controls
    By Jeremy Gollehon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2005, 10:06 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