1

the following code works:

Dim strNew As String
strNew = "xxyy"
strNew = Replace (strNew, "y", "z")

But this one doesn't, i get a syntax error:

Dim strNew As String
strNew = "xxyy"
strNew = Replace expression:=strNew, find:="y", replace:="z"

This is the description of the Replace Function (part of vba.strings) according to "help" (F2):

Function Replace(Expression As String, Find As String, Replace As String, [Start As Long = 1], [Count As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare]) As String

Element von VBA.Strings

Find and replace a substring within a string

I don't understandy why there is an error?

Community
  • 1
  • 1
Rasputin221
  • 51
  • 1
  • 3
  • 6
    You took the brackets out... – Rory Sep 13 '19 at 10:49
  • 5
    When you call a function/procedure you can pass it's arguments without brackets, but if you are giving it to a variable, you must use brackets. – Damian Sep 13 '19 at 10:50
  • You could still do `strNew = Replace(expression:=strNew, find:="y", replace:="z")` or `strNew = Replace strNew, "y", "z"` – L8n Sep 13 '19 at 12:16
  • 1
    Possible duplicate of [What are the rules governing usage of brackets in VBA function calls?](https://stackoverflow.com/questions/5413765/what-are-the-rules-governing-usage-of-brackets-in-vba-function-calls) – L8n Sep 13 '19 at 12:18

0 Answers0