LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Deactivating a Forms macro button based on a worksheet condition?

Thanks for the suggestions.
I got the first suggestion working as I can easily make the change to
the macro script (I have little paractical VB experience). However, I
am now thinking I need to go one better and get the same thing
happening on a CommandButton from the Controls Toolbox. I searched on
this forum and found some very nice things you can do with the
CommandButtons that you can't do with the the Forms buttons.
eg. You can disable the CommandButton, the text on it can be greyed
out and display a custom message alerting the user to the reason why
the button is disabled. Here is some script that I found that does
this (I don't fully understand it but i can get it to work if i just
copy and paste):

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCellsToCheck As Range
Set myCellsToCheck = Me.Range("a1,b2")

If Intersect(Target, myCellsToCheck) Is Nothing Then
Exit Sub
End If

'Top one is for the Forms toolbar
' bottom one used the control toolbox toolbar
'With Me.Buttons("button 2")
With Me.CommandButton1
Select Case Application.CountA(myCellsToCheck)
Case Is = 0:
.Enabled = True
.Caption = "click me to run macro"
Case Is = 1
.Enabled = False
.Caption = "Clear other cell" & vbLf & "before
running"
Case Is = 2
.Enabled = False
.Caption = "Clear both cells " &
myCellsToCheck.Address(0, 0) _
& vbLf & " before clicking"
End Select
End With

End Sub

Now, I am hoping to maybe combine the cool greying out/custom message
you can get on the button above, with the suggested disable/enable
script based on A1 being TRUE or not suggested below.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A1").Value = True Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub

this will disable/enable the button on the sheet.

regards
FSt1


I do need to also learn how to assign a macro to a CommandButton. I
know you are meant to assign the macro to the event on click feature
but I don't know the syntax to do that. I do knwo that a line or two
needs to be added.....

Private Sub CommandButton1_Click()
[inbetween here!!!!!!]
End Sub

....when you double click the CommandButton.

Any further help much appreciated.

Cheers

Ace70

 
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
Tooltip for macro button in a worksheet Manju Excel Worksheet Functions 0 February 1st 07 06:41 PM
Use of Forms Command-button on Worksheet Jim May Excel Discussion (Misc queries) 12 November 13th 06 06:08 PM
copy data from 1 worksheet to another based on a condition [email protected] Excel Worksheet Functions 9 September 4th 06 02:45 PM
Adding Macro to Button on WOrksheet Barb Reinhardt Excel Discussion (Misc queries) 1 January 21st 06 02:29 PM
how to hide section of worksheet based on a condition (e.g. tick . kitepuppet Excel Discussion (Misc queries) 2 March 4th 05 06:30 PM


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

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"