Exclude One Textbox from a Collection of Controls

jtrombley24

New Member
Joined
Feb 21, 2016
Messages
27
This shouldn't be hard, but it's giving me fits.

This code is working well and I'm creating a collection of textbox controls so that I can detect changes on the userform (to prompt a user to save their work).

I want to EXCLUDE one textbox (that I'm using as a search feature) from the collection so that changes are NOT detected when a user begins typing.

I know this should be easy, but I'm stumped. Thanks in advance!

Code:
    Set tbCollection = New Collection

        For Each ctrl In Me.Controls
            
            If TypeOf ctrl Is MSForms.TextBox Then

                Set obj = New ClsFormChanges
                Set obj.ControlTB = ctrl
                tbCollection.Add obj

            End If
            
        Next ctrl

    Set obj = Nothing
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Can you identify the textbox you want to include in some way, perhaps it's name?

If you can then you could use something like this.
Code:
    Set tbCollection = New Collection

        For Each ctrl In Me.Controls
            
            If TypeOf ctrl Is MSForms.TextBox Then

                If ctrl.Name <> "NameOfTextBoxIWantToExclude" Then
                    Set obj = New ClsFormChanges
                    Set obj.ControlTB = ctrl
                    tbCollection.Add obj
                End If

            End If
            
        Next ctrl

    Set obj = Nothing
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top