Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I use the Indirect Function in Excel VBA to incorporate the equations in a VBA Macro Function

(A7) value = JohnWinstonLennon

These Excel worksheet equations work just fine on the base Excel Worksheet. Both equations give the location for the 2nd and 3rd Capital Letters in a run-on String, such as the one above.

I am trying to write them into a function with VBA, but I cannot figure out how to make the Indirect reference work in the function. Any Help, Please!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

=SMALL(FIND(0,SUBSTITUTE(A7,CHAR(ROW(INDIRECT("65:90"))),0)&0),2)  
=SMALL(FIND(0,SUBSTITUTE(A7,CHAR(ROW(INDIRECT("65:90"))),0)&0),3) 

>Solution :

If you trying to write a function using VBA, then maybe give the following a try:

Sub Test()

Dim str As String: str = "JohnWinstonLennon"

With CreateObject("vbscript.regexp")
    .Global = True
    .Pattern = "[A-Z]"
    If .Test(str) Then
        Set matches = .Execute(str)
        For Each Match In matches
            Debug.Print Match.FirstIndex + 1
        Next
    End If
End With

End Sub

You could rework this into an UDF to return the position of the nth capital?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading