Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do you programmatically hide/unhide a command button in Excel?

Hello,

I have a command button in excel that i want to be hidden initially, until
another cell in the worksheet is a 3. How do I go about doing this in VBA?

Thank you!
MN


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default How do you programmatically hide/unhide a command button in Excel?

If the value in the cell changes to 3 based on the user typing, I'd use a
Worksheet_Change event.

If you want to try, rightclick on the sheet tab that should have this behavior
and select View Code. Paste this into the code window that opened (usually on
the right hand side of the screen):

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
Set myCell = Me.Range("A1")
If Intersect(myCell, Target) Is Nothing Then
Exit Sub
End If

If myCell.Value = 3 Then
Me.CommandButton1.Visible = True
Else
Me.CommandButton1.Visible = False 'rehide it if the value changes???
End If
End Sub

On the other hand, if the value changes as a result of a formula, you could use
a different worksheet event:

Option Explicit
Private Sub Worksheet_Calculate()

Dim myCell As Range
Set myCell = Me.Range("A1")

If myCell.Value = 3 Then
Me.CommandButton1.Visible = True
Else
Me.CommandButton1.Visible = False 'rehide it if the value changes???
End If
End Sub



On 05/17/2010 14:37, MacNut2004 wrote:
Hello,

I have a command button in excel that i want to be hidden initially, until
another cell in the worksheet is a 3. How do I go about doing this in VBA?

Thank you!
MN


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
command button to unhide row Marilyn Excel Discussion (Misc queries) 1 July 28th 08 11:16 PM
Hide and Unhide Rows button FinlandGuy Excel Programming 6 December 12th 07 11:58 AM
Activex command to Hide/Unhide Scafidel Excel Worksheet Functions 3 February 16th 07 01:40 AM
Command Button to Hide/Unhide Rows Bea Excel Discussion (Misc queries) 4 March 16th 06 03:21 PM
Hide and unhide command gridlines etc... Michael Vautour Excel Programming 0 August 28th 03 09:00 PM


All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"