View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default Gotta be some more Efficient code

this worked for me

Private Sub CommandButton1_Click()
Dim i As Long

For i = 1 To 10
If Len(Trim(Me.Controls("label" & i).Caption)) 0 Then
Me.Controls("textbox" & i).Visible = True
Else
Me.Controls("textbox" & i).Visible = False
End If
Next
End Sub

--


Gary


"Jennifer" wrote in message
...
I have 10 text boxes is there a more efficient way to write this code.
Eventually there could be more textboxes and labels. Loop? Thank you so much.

If Len(Trim(Label1.Caption)) 0 Then
TextBox1.Visible = True
Else
TextBox1.Visible = False
End If
If Len(Trim(Label2.Caption)) 0 Then
TextBox2.Visible = True
Else
TextBox2.Visible = False
End If
--
Thank you,

Jennifer