Show and Hide TextBox VBA code

adi_asja

New Member
Joined
Mar 30, 2014
Messages
3
Great to join this forum & hoping for helps.
I'm trying to arrange 2 VBA code to show and hide the Text Boxes and using 2 auto shapes to executed the macros. Are there any simple VBA code or shorter than below code to doing this? Thanks for advance..

Code:
Sub Show_Box()​
' Show cell value in the textbox​
Sheets(1).Shapes("TextBox" & 1).Visible = True
Sheets(1).Shapes("TextBox" & 2).Visible = True
Sheets(1).Shapes("TextBox" & 3).Visible = True​
End Sub​

Sub Hide_Box()​
' Show cell value in the textbox​
Sheets(1).Shapes("TextBox" & 1).Visible = False
Sheets(1).Shapes("TextBox" & 2).Visible = False
Sheets(1).Shapes("TextBox" & 3).Visible = False​
End Sub​
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can do it like this:

Code:
Sub ShowHide_TextBox(byval ShowTextBox as Boolean)
      Sheets(1).Shapes.range(array("TextBox1", "TextBox2", "TextBox3")).Visible = ShowTextBox 
End Sub
 
Upvote 0
thanks to the reply mohan.

I am newbie in VB,
I just pasted your code in a new module, but when I tried to assign the macro, it is nothing appear.
Suggestion please, how to apply your code?

Thanks lot
 
Upvote 0
You need to run that code like this

Code:
Option Explicit
Sub ShowHide_TextBox(ByVal ShowTextBox As Boolean)
      Sheets(1).Shapes.Range(Array("TextBox1", "TextBox2", "TextBox3")).Visible = ShowTextBox
End Sub


Sub x()
ShowHide_TextBox False
End Sub
Sub y()
ShowHide_TextBox True
End Sub

This code will toggle the TextBoxes visibilyt



Code:
Sub Toggle_Boxes()
Sheets(1).Shapes.Range(Array("TextBox1", "TextBox2", "TextBox3")).Visible = Not _
    Sheets(1).Shapes.Range(Array("TextBox1", "TextBox2", "TextBox3")).Visible
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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