Maxwell
Maxwell

Reputation: 109

Replace Compile Error: Wrong number of arguments or invalid property assignment

I'm having trouble compiling my code

Dim OriginalText As String
Dim CorrectedText As String

OriginalText = Range("A5").Value

CorrectedText = Replace(OriginalText, "a", "o")

Range("A5").Offset(, 1).Value = CorrectedText

In Cell A5 I have the word Micrasaft and I want to replace with Microsoft.

I get 'Compile error: Wrong number of arguments or invalid property assignment'.


I know why, because I called my Sub Replace, didn't know that if you name your sub the same way a formula, it won't compile

Upvotes: 2

Views: 4896

Answers (1)

MartinB
MartinB

Reputation: 48

Try the following way:

Dim OriginalText As String
Dim CorrectedText As String

OriginalText = Range("A5").Value

CorrectedText = VBA.Strings.Replace(OriginalText, "a", "o")

Range("A5").Offset(, 1).Value = CorrectedText

Upvotes: 2

Related Questions