need help

chobanne

Active Member
Joined
Jul 3, 2011
Messages
269
i have 2 codes

first

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Range("E33") = 1 Then
CommandButton3.Visible = False
CommandButton4.Visible = False
ActiveSheet.Shapes("OKVIR2").Visible = False
Else
CommandButton3.Visible = True
CommandButton4.Visible = True
ActiveSheet.Shapes("OKVIR2").Visible = True
End If
End Sub

and second

Private Sub Worksheet_SelectionChange2(ByVal Target As Excel.Range)
If Range("E34") = 1 Then
CommandButton7.Visible = False
Else
CommandButton7.Visible = True
End If
End Sub

first is working, second dont, anyone know why? where is mistake?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I can only imagine it is because you have named the second sub routine "SelectionChange2" which will not automatically fire on the selection changed event.

You would want to do it all under the first one:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
 
If Range("E33") = 1 Then
    CommandButton3.Visible = False
    CommandButton4.Visible = False
    ActiveSheet.Shapes("OKVIR2").Visible = False
Else
    CommandButton3.Visible = True
    CommandButton4.Visible = True
    ActiveSheet.Shapes("OKVIR2").Visible = True
End If
 
If Range("E34") = 1 Then
    CommandButton7.Visible = False
Else
    CommandButton7.Visible = True
End If
 
End Sub

Try to indent your code otherwise it makes it more difficult for people to read.
 
Upvote 0
You can only have one worksheet change procedure per sheet. The body of your second piece of code needs to be copied into the first bot of code.
You could Also do with checking whether or not either of those cells are changed before you bother running that ode though.
 
Upvote 0
I can only imagine it is because you have named the second sub routine "SelectionChange2" which will not automatically fire on the selection changed event.

You would want to do it all under the first one:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
 
If Range("E33") = 1 Then
    CommandButton3.Visible = False
    CommandButton4.Visible = False
    ActiveSheet.Shapes("OKVIR2").Visible = False
Else
    CommandButton3.Visible = True
    CommandButton4.Visible = True
    ActiveSheet.Shapes("OKVIR2").Visible = True
End If
 
If Range("E34") = 1 Then
    CommandButton7.Visible = False
Else
    CommandButton7.Visible = True
End If
 
End Sub

Try to indent your code otherwise it makes it more difficult for people to read.

you are right, i ll keep it on my mind in future. It works but i have little problem with command button7 again. it will disapear or appear only if i start clicking on random cell in my sheet. there is no problem with cb3 and cb4. you know how to handle with this
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,611
Members
452,931
Latest member
The Monk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top