Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default hiding a control depending on a cell's value

hi,
i have a few command buttons created directly on the spreadsheet
(not through userforms). i need to have the buttons appears and
disappear depending on a cell's value. ex. if the cell value = 1, have
the buttons become visible and invisible if any other value. visible
or enabled..either is fine.
the code i am using is this but i can't seem to get it to work. i am
using excel 2002. appreciate any help. thanks.

Private Sub Worksheet_Activate()
If Target.Address = "n40" and Target.Value = 1 Then
Worksheets("Sheet1").CommandButton("button1").Enab led = True
Else
Worksheets("Sheet1").CommandButton("button1").Enab led = False
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default hiding a control depending on a cell's value

Try

Private Sub Worksheet_Change(ByVal Target As Range)

With Target
If .Address = "$N$40" And .Value = 1 Then
Me.Buttons("Button 1").Enabled = True
Else
Me.Buttons("Button 1").Enabled = False
End If
End With

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"yoram" wrote in message
oups.com...
hi,
i have a few command buttons created directly on the spreadsheet
(not through userforms). i need to have the buttons appears and
disappear depending on a cell's value. ex. if the cell value = 1, have
the buttons become visible and invisible if any other value. visible
or enabled..either is fine.
the code i am using is this but i can't seem to get it to work. i am
using excel 2002. appreciate any help. thanks.

Private Sub Worksheet_Activate()
If Target.Address = "n40" and Target.Value = 1 Then
Worksheets("Sheet1").CommandButton("button1").Enab led = True
Else
Worksheets("Sheet1").CommandButton("button1").Enab led = False
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default hiding a control depending on a cell's value

i tried this and keep getting a "Method 'Buttons' of object
'_Worksheet' failed" error...any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default hiding a control depending on a cell's value

Perhaps it is buttons from the control toolbox

Private Sub Worksheet_Change(ByVal Target As Range)

With Target
If .Address = "$N$40" And .Value = 1 Then
Me.OLEObjects("CommandButton1").Enabled = True
Else
Me.OLEObjects("CommandButton1").Enabled = False
End If
End With

End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"yoram" wrote in message
ups.com...
i tried this and keep getting a "Method 'Buttons' of object
'_Worksheet' failed" error...any ideas?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default hiding a control depending on a cell's value

that works in changing the button to inactive but unfotunately it
changes to inactive as soon as any cell value is changed. it does not
change back to active regardless of the linked cell's value.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default hiding a control depending on a cell's value

Unless the linked cell is N40 I don't see the connection. That code will
only toggle the button state depending on the change of the value in N40 to
1 or not 1.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"yoram" wrote in message
oups.com...
that works in changing the button to inactive but unfotunately it
changes to inactive as soon as any cell value is changed. it does not
change back to active regardless of the linked cell's value.



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
Selecting a cell depending on the other cell's value, kind of wally_91[_4_] Links and Linking in Excel 2 April 2nd 08 05:12 PM
How can I change a picture depending on a cell's contents LEP Excel Discussion (Misc queries) 1 December 23rd 07 12:16 AM
CONDITIONAL RESULTS DEPENDING ON CELL'S NAME (sumproduct) HERNAN Excel Discussion (Misc queries) 4 September 5th 06 09:02 PM
How do I get a cell to flash depending on another cell's value? trrrr Excel Worksheet Functions 3 May 8th 06 06:41 PM
autowrite a cell depending on another cell's content jose carreno Excel Programming 2 October 1st 03 05:50 PM


All times are GMT +1. The time now is 08:00 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"