If tab becomes hidden then...

Rowanhf12

New Member
Joined
Jan 22, 2016
Messages
27
So a have code written in tab 'sheet1'. And Basically if the tab becomes hidden, I want the word 'No' written in the tab 'info'. And when the tab becomes unhidden, I want the word 'Yes' written in the tab 'info'. At the moment, when i unhide/hide 'sheet1' nothing happens.

Code:
Private Sub Worksheet_Change()
If ActiveSheet.Visible = True Then
    Sheets("Info").Visible = True
    ActiveSheet.Range("D2").Select
    ActiveCell.FormulaR1C1 = "Yes"
    Sheets("Info").Visible = False
ElseIf ActiveSheet.Visible = False Then
    Sheets("Info").Visible = True
    ActiveSheet.Range("D2").Select
    ActiveCell.FormulaR1C1 = "No"
    Sheets("Info").Visible = False
End If
End Sub
 
you're using activesheet.range("D2") instead of
sheets("Info").activate
then activesheet ect
the active sheet at the time of the code being run is the active sheet. You have not activated Info, just ensured it is visible.
 
Upvote 0
Code:
Put this in sheet info code 

Private Sub Worksheet_Activate()
If Sheet1.Visible = False Then
        Sheets("info").Range("a1").Value = "NO"
Else
Sheets("info").Range("a1").Value = "YES"
End If
End Sub
 
Upvote 0
Yea, my bad. Thanks for you help. Have updated that. But still nothing happens.

Code:
Private Sub Worksheet_Change()
If ActiveSheet.Visible = True Then
    Sheets("Info").Visible = True
    Sheets("Info").Range("D2").Select
    ActiveCell.FormulaR1C1 = "Yes"
    Sheets("Info").Visible = False
ElseIf ActiveSheet.Visible = False Then
    Sheets("Info").Visible = True
    Sheets("Info").Range("D2").Select
    ActiveCell.FormulaR1C1 = "No"
    Sheets("Info").Visible = False
End If
End Sub
 
Upvote 0
Thank you MandeepBaluja

Actually works perfectly if I put the code in Info tab instead. If i put it in Sheet1, then it works when the tab is unhidden, but fails to work when hidden.

Much appreciate your help
 
Upvote 0

Forum statistics

Threads
1,226,868
Messages
6,193,435
Members
453,799
Latest member
shanley ducker

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