Is there an if statement to test for worksheet visibility?

spurs

Active Member
Joined
Oct 18, 2006
Messages
479
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
  5. 2003 or older
Platform
  1. Windows
Is there a way to use a worksheet formula (not in VBA) to test if a worksheet is visible.

For example something like

If worksheet A is visible then = 'A'!B2

but as an equation to put in a cell?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
what is it you are trying to achieve ?
 
Upvote 0
I have a worksheet named "A" , "B" and "C"

Only A or B will be visible at once. C is always visible

If worksheet A is visible than I want to transfer the value in cell B2 from worksheet A to worksheet C cell B2
If worksheet B is visible than I want to transfer the value in cell B2 from worksheet B to worksheet C cell B2
 
Upvote 0
I don't think you can check for sheet visibility using a standard worksheet formula.

You could, however, use a custom VBA function that works exactly like a worksheet function:

Code:
Public Function ISVISIBLE(SheetName As String)

' Returns TRUE if the given sheet
' is visible or FALSE otherwise

  Dim x As Object
  Application.Volatile
  
  On Error Resume Next
  Set x = Application.Caller.Parent.Parent.Sheets(SheetName)
  If Err.Number <> 0 Then
    ISVISIBLE = CVErr(xlErrName)
    Exit Function
  End If
  
  On Error GoTo 0
  If x.Visible = xlSheetVisible Then
    ISVISIBLE = True
  Else
    ISVISIBLE = False
  End If

End Function
 
Upvote 0
Or similarly,

Code:
Public Function IsVisible(r As Range)
  Application.Volatile
  IsVisible = r.Worksheet.Visible = xlSheetVisible
End Function

E.g., =IsVisible(Sheet1!A1)

Hiding a sheet doesn't trigger calculation, though, so it won't automatically update when a sheet is hidden, despite being volatile.
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,218
Members
449,091
Latest member
jeremy_bp001

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