Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90185

how can i pass a optional value to a sub?

$
0
0

I am trying to use a sub. Maybe I should do it as a function because I will be calling this many different times.

But for now it's a sub, unless that is why it's not working?

I'm passing two sheet names via macro, to show one sheet, then hide the previous one.

However, I get the error "Expected = "

Code is below, any ideas?

Sub setupToFront()

    showsheet ("Status","Setup")

End Sub


Sub showsheet(mySheet As String, Optional ByVal hidesheet As Variant)

Dim ws As Worksheet
Set ws = Worksheets(mySheet)

ws.Visible = xlSheetVisible
ws.Activate

If IsMissing(hidesheet) Then
    'nothing, optional val not used
Else
    Worksheets(CStr(hidesheet)).Visible = xlSheetHidden
End If

End Sub

Viewing all articles
Browse latest Browse all 90185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>