Sourav Bhattacharya
Sourav Bhattacharya

Reputation: 1

Not able to use a variable inside Find command in VBA

I have a string s which contains "subham$"

Now using excel's built in command find i like to know the position of the dollar symbol,there might be other ways but i like to use find in vba code and use a variable inside it

Sub testfind()
    Dim s As String
    s = "subham$"
    Sheets("Sheet1").Select
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "=FIND(""$""," & s & ")"
End Sub

I am getting the error Application defined or object defined error, what am I doing wrong?

Upvotes: 0

Views: 52

Answers (1)

CLR
CLR

Reputation: 12279

I can't actually fathom what you're trying to do with the code, or why you'd be doing it, but in order to solve your problem:

You're not wrapping the string of s in quotes. Try:

Range("A1").FormulaR1C1 = "=FIND(""$"",""" & s & """)"

Upvotes: 1

Related Questions