problem with code

chobanne

Active Member
Joined
Jul 3, 2011
Messages
269
hello all

I make this code and have problem with it

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Range("ah1") = 1 Then
ActiveSheet.Shapes("Picture 15").Visible = True
Else:
ActiveSheet.Shapes("Picture 15").Visible = False
End If
End Sub

The picture don't automatically hide or unhide until i click some random cell in sheet.

Can someone pls help me what to add in code to avoid subsequent click
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi
Try
VBA Code:
Private Sub Worksheet_Change(....)
 
Upvote 0
Is there a cell on the sheet that you are changing and is meant to trigger the code ?
(the change needs to be a manual change and not a formula, if a formula is there a cell that is manually changed that drives the formula)

Maybe:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Not Intersect(Target, Range("AH1")) Is Nothing Then
        If Range("AH1") = 1 Then
            ActiveSheet.Shapes("Picture 15").Visible = True
        Else:
            ActiveSheet.Shapes("Picture 15").Visible = False
        End If
    End If
End Sub
 
Last edited:
Upvote 0
Is there a cell on the sheet that you are changing and is meant to trigger the code ?
(the change needs to be a manual change and not a formula, if a formula is there a cell that is manually changed that drives the formula)
Yes there is cell AH1 with formula =IF(AG=TRUE,1,0)
 
Upvote 0
Is there a cell on the sheet that you are changing and is meant to trigger the code ?
(the change needs to be a manual change and not a formula, if a formula is there a cell that is manually changed that drives the formula)

Maybe:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Not Intersect(Target, Range("AH1")) Is Nothing Then
        If Range("AH1") = 1 Then
            ActiveSheet.Shapes("Picture 15").Visible = True
        Else:
            ActiveSheet.Shapes("Picture 15").Visible = False
        End If
    End If
End Sub
the code is not working
 
Upvote 0
With your original code, it will run the code everytime you move around the sheet (in fact any random cell).
Of course if AH1 doesn't change it should do the same thing each time so there should be no visible change on the spreadsheet.

Worksheet_Change only runs when you actually change something on the worksheet.
What makes AG change ? Is it also a formula ? Actually it can't be AG that is not valid, what is the actual cell reference in AG
 
Upvote 0
With your original code, it will run the code everytime you move around the sheet (in fact any random cell).
Of course if AH1 doesn't change it should do the same thing each time so there should be no visible change on the spreadsheet.

Worksheet_Change only runs when you actually change something on the worksheet.
What makes AG change ? Is it also a formula ? Actually it can't be AG that is not valid, what is the actual cell reference in AG
checkbox click
 
Upvote 0
Do you know if its an ActiveX check box or a Forms check box ?
If its ActiveX in the same module as the worksheet event copy in this.

The checkbox name needs to match.

Rich (BB code):
Private Sub CheckBox1_Click()
        If Range("AH1") = 1 Then
            ActiveSheet.Shapes("Picture 15").Visible = True
        Else:
            ActiveSheet.Shapes("Picture 15").Visible = False
        End If
End Sub
 
Upvote 0
Do you know if its an ActiveX check box or a Forms check box ?
If its ActiveX in the same module as the worksheet event copy in this.

The checkbox name needs to match.

Rich (BB code):
Private Sub CheckBox1_Click()
        If Range("AH1") = 1 Then
            ActiveSheet.Shapes("Picture 15").Visible = True
        Else:
            ActiveSheet.Shapes("Picture 15").Visible = False
        End If
End Sub
its form check box, thats why i have AH1 value, For activex i dont need range AH1 i think, i think code must be modify
 
Upvote 0

Forum statistics

Threads
1,215,151
Messages
6,123,316
Members
449,094
Latest member
Chestertim

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