Consulting

Results 1 to 2 of 2

Thread: hide/unhide textbox

  1. #1
    VBAX Regular
    Joined
    Nov 2008
    Posts
    35
    Location

    hide/unhide textbox

    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

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi there,

    Presuming you mean activex textboxes, maybe something like:

    [vba]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[/vba]

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

    Hope that helps,

    Mark
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •