Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 460
Default Macro Button

I have a macro assigned to a button. I want the button to disappear if a
condition exists. For example if some cell value = "Y" I want the button to
not be present. If the cell value = "N" (or not "Y") I want the button to be
active. Does anyone have an idea on how to do that?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Macro Button

You can use

CommandButton1.Visible = False



If you don't want this to appear/not appear on loading your form you should
do something like this:

Sub Userform_Initialize

If range("A1").value = "N" then
CommandButton1.Visible = False
end if


End Sub

--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Macro Button

On Oct 17, 8:53 am, "Crowbar via OfficeKB.com" <u15117@uwe wrote:
You can use

CommandButton1.Visible = False

If you don't want this to appear/not appear on loading your form you should
do something like this:

Sub Userform_Initialize

If range("A1").value = "N" then
CommandButton1.Visible = False
end if

End Sub

--
Message posted viahttp://www.officekb.com


Hello Doug,

If your button is on a Worksheet then you will need a second macro to
check the cell's value and change the button's Visible property. This
second macro will need to run during the Worksheet_Activate() event,
and the Worksheet_Change() event. The code for both types of buttons
is provided. You may need to change the cell address that is checked,
and the button's name (only if it is different, and is a Control
Toolbox type).

'Second macro code. Place this in a Standard VBA Module

' Use this code if the Button is from the FORMS Toolbar
Public Sub HideUnhideButton()

With ActiveSheet
If .Range("A1") = "Y" Then
.DropDowns(Application.Caller).Visible = True
Else
.DropDowns(Application.Caller).Visible = False
End If
End With

End Sub

' Use this code if the Button is from the CONTROL TOOLBOX
Public Sub HideUnhideButton()

Dim Btn As MSForms.CommandButton

With ActiveSheet
Set Btn = .OLEObjects("CommandButton1").Object 'Change
the name of the Command button if needed
If .Range("A1") = "Y" Then
Btn.Visible = True
Else
Btn.Vsible = False
End If
End With

End Sub

'Event Code Procedures

Private Sub Worksheet_Change(BYVal Target As Range)

If Target.Address = "$A$1" Then Call HideUnhideButton

End Sub

Private Sub Worksheet_Activate()

Call HidenHideButton

End Sub

Sincerely,
Leith Ross

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 460
Default Macro Button

Dear Leith: Thank you so much for your response. The button is from the Forms
toolbar and needs to reference three cells (A1,B1,B2). If either of the cells
has a value = "Y" then the button would disappear. How would I imbed an or
statement within the VBA code? Also, you said modify a standard module...Do I
get there by selecting ToolsMacroVB Editor? If so which sheet do I modify?

Doug

"Leith Ross" wrote:

On Oct 17, 8:53 am, "Crowbar via OfficeKB.com" <u15117@uwe wrote:
You can use

CommandButton1.Visible = False

If you don't want this to appear/not appear on loading your form you should
do something like this:

Sub Userform_Initialize

If range("A1").value = "N" then
CommandButton1.Visible = False
end if

End Sub

--
Message posted viahttp://www.officekb.com


Hello Doug,

If your button is on a Worksheet then you will need a second macro to
check the cell's value and change the button's Visible property. This
second macro will need to run during the Worksheet_Activate() event,
and the Worksheet_Change() event. The code for both types of buttons
is provided. You may need to change the cell address that is checked,
and the button's name (only if it is different, and is a Control
Toolbox type).

'Second macro code. Place this in a Standard VBA Module

' Use this code if the Button is from the FORMS Toolbar
Public Sub HideUnhideButton()

With ActiveSheet
If .Range("A1") = "Y" Then
.DropDowns(Application.Caller).Visible = True
Else
.DropDowns(Application.Caller).Visible = False
End If
End With

End Sub

' Use this code if the Button is from the CONTROL TOOLBOX
Public Sub HideUnhideButton()

Dim Btn As MSForms.CommandButton

With ActiveSheet
Set Btn = .OLEObjects("CommandButton1").Object 'Change
the name of the Command button if needed
If .Range("A1") = "Y" Then
Btn.Visible = True
Else
Btn.Vsible = False
End If
End With

End Sub

'Event Code Procedures

Private Sub Worksheet_Change(BYVal Target As Range)

If Target.Address = "$A$1" Then Call HideUnhideButton

End Sub

Private Sub Worksheet_Activate()

Call HidenHideButton

End Sub

Sincerely,
Leith Ross


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
Use Macro To Change Which Macro Assigned To Command Button CVinje Excel Discussion (Misc queries) 0 May 25th 10 09:55 PM
Creating a macro which presses a button containing a recorded macro petros89[_3_] Excel Programming 3 October 5th 05 02:49 PM
Can't select macro button after other button is pressed C. Campbell Excel Programming 1 November 30th 04 07:46 PM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar[_15_] Excel Programming 1 May 26th 04 09:45 AM
How to end macro on inital active worksheet containing macro button that was clicked Silverhawk1 Excel Programming 2 May 14th 04 03:58 PM


All times are GMT +1. The time now is 02:12 AM.

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

About Us

"It's about Microsoft Excel"