Validate Excel Range with RegEx

  • Thread starter Thread starter Fletch
  • Start date Start date
F

Fletch

Any thoughts on how to validate an Excel range with RegEx?
Acceptable inputs would include $A1:$BD25, C:C, B4 etc.
I'm close to coming up with an answer but I'm not sure how to stop
invalid range references such as C3:A2 from being accepted.

Thanks.
 
You could try something like this. But be aware that "C3:A2" is a perfectly
valid range string. Even thought Excel will turn it around for
presentation/display purposes that doesn't mean it's invalid.

Sub Test()
MsgBox RgValid("ZC3:A2")
End Sub

Function RgValid(RgStr) As Boolean
Dim Rg As Range
On Error GoTo ExitThis
Set Rg = Range(RgStr)
RgValid = True
Exit Function
ExitThis:
End Function
 
Back
Top