OzGrid

How to make all empty textboxes invisible

< Back to Search results

 Category: [Excel]  Demo Available 

How to make all empty textboxes invisible

 

Requirement:

 

The user has a form with a number of textboxes on it.

After they have been populated, any of them that are blank need to be invisible.

The next textbox also needs to be invisible.

 

Solution:

 

What the user could possibly do (again, not really enough info to be sure) is populate the textboxes then loop though all controls setting those textboxes that are blank to be hidden.

Code:
Dim c as Control

For Each c in Me.Controls
    If typeName(c) = "TextBox" Then
        c.Visible = (c.Text <> vbNullstring)
    End If
Next

 

If there are other textboxes on the userform you do not want to be affected by this then you will have to add another check. Perhaps add a '*' to the tag property of those and check the Tag in the loop.

 

Obtained from the OzGrid Help Forum.

Solution provided by cytop.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to search ListBox as the user types in TextBox
How to calculate userform textbox and cell value for label caption
How to select an option in the combobox and the textboxes to auto-fill with data

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 

 


Gallery



stars (0 Reviews)