PDA

View Full Version : hide/unhide textbox



suji
01-21-2013, 01:41 AM
Hi,

This is what I am trying to do...

unhide few texboxes if their names are present in any cells between A1:Z1.. if textbox names are not present then hide textbox. If all cells are blank then hide all textboxes.

Thanks
Suji

GTO
01-21-2013, 04:33 PM
Hi there,

Presuming you mean activex textboxes, maybe something like:

Option Explicit

Private Sub CommandButton1_Click()
Dim obj As OLEObject
Dim arrNames As Variant
Dim n As Long

arrNames = Me.Range("A1:Z1").Value
For n = 1 To UBound(arrNames, 2)
arrNames(1, n) = LCase(Trim(arrNames(1, n)))
Next

For Each obj In Me.OLEObjects
If TypeName(obj.Object) = "TextBox" Then
obj.Visible = _
Not IsError(Application.Match(LCase(obj.Name), Application.Index(arrNames, 1, 0), 0))
End If
Next
End Sub

Private Sub CommandButton2_Click()
Dim obj As OLEObject

For Each obj In Me.OLEObjects
If TypeName(obj.Object) = "TextBox" Then
obj.Visible = True
End If
Next
End Sub

I wasn't sure, but guessed that we would like to keep it case-insensitive.

Hope that helps,

Mark