Excel VBA Tell if string is R1C1 Reference

Hi

I have a string sRange that holds a range. If it holds eg R[-1]C[+2] what VBA would I use
to test if it is an R1C1 reference?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

if you are already in R1C1 mode
Sub Macro()
srange = "R[-1]C[+2]"
res = Evaluate("=isref(" & srange & ")")
End Sub

Open in new window

Regards
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks. If I run that code and hover over res I see the value "Error 2015"
0
Rgonzo1971Commented:
then try
Sub Macro1()
    Dim regex As Object
    Set regex = CreateObject("VBScript.RegExp")
    srange = "R[-1]C[+2]"
    With regex
        .Global = True
        .IgnoreCase = True
        .Pattern = "^R((\[[+-]?\d+\])|\d+)?C((\[[+-]?\d+\])|\d+)?"
    End With
    res = regex.Test(srange)
    
    Set regex = Nothing

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
I am amazed! Thank you very much. Fantastic answer!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.