ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide/Unhide CommandButton by cell criteria (https://www.excelbanter.com/excel-programming/420059-hide-unhide-commandbutton-cell-criteria.html)

cru

Hide/Unhide CommandButton by cell criteria
 
Can i have more than two range under SelectionChage?

I currently have this code but I got the first two range to work but the
third range does not work:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("D18").Value = "YES" Then
Me.CommandButton13.Visible = True
Else
Me.CommandButton13.Visible = False
End If
If Range("D19").Value = "YES" Then
Me.CommandButton28.Visible = True
Else
Me.CommandButton28.Visible = False
End If
If Range("D21").Value = "YES" Then
Me.CommandButton29.Visible = True
Else
Me.CommandButton29.Visible = False
End If
End Sub

Mike H

Hide/Unhide CommandButton by cell criteria
 
Hi,

That should work perfectly but if it doesn't consider the following

the YES in the cells must be uppercase
Ensure you have the correct commandbutton number in your code
The use of ME isn't necessary but shouldn't cause a problem

Mike

"cru" wrote:

Can i have more than two range under SelectionChage?

I currently have this code but I got the first two range to work but the
third range does not work:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("D18").Value = "YES" Then
Me.CommandButton13.Visible = True
Else
Me.CommandButton13.Visible = False
End If
If Range("D19").Value = "YES" Then
Me.CommandButton28.Visible = True
Else
Me.CommandButton28.Visible = False
End If
If Range("D21").Value = "YES" Then
Me.CommandButton29.Visible = True
Else
Me.CommandButton29.Visible = False
End If
End Sub



All times are GMT +1. The time now is 01:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com