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

Ignore optional argument of a custom Sub

$
0
0

I have a custom sub that takes a required argument and an optional one:

    Sub selectRange(txtbox As MSForms.TextBox, Optional lbl As MSForms.Label)

This works just fine, but the thing is - have to pass both arguments or else I get an error. The error is understandable given the fact that the sub contains lines that directly refer to the optional argument (lbl), lines like:

If Len(s) = 0 Then
    lbl.ForeColor = RGB(255, 0, 0)
    lbl.Font.Italic = True
    lbl.Caption = "{!this range doesn't contain values!}"
    Exit Sub
End If

The optional argument is referred to in a number of other places in the code (pretty much scattered here and there...)

What sort of modifications do I need to make in my code so that selectRange can operate smoothly in cases where just the required argument is passed/needed?

Thanks!


Viewing all articles
Browse latest Browse all 88030

Trending Articles



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