RedditPP Mascot

RedditPP

r/excel • … • u/xile

Excel adds the "Implicit Intersection Operator", @, to my function when using VBA .Replace

I am using .Replace within a VBA script to change an argument within an index formula. After running the script, Excel is adding the @ to the beginning of my formula, and also the beginning of existing named ranges within other arguments. This formula then returns a #NA instead of the wanted value.

Existing formula:

=INDEX(_Total_Unit_Qty,MATCH(1,($C$54=_Product6N)*($C56=_OptionXXX),0))

VBA:

Findtext = "_Total_Unit_Qty" Replacetext = "INDEX(_Unit_Qty,," & Unit_Index & ")" Sheets(SheetName).Range("B55").Replace what:=Findtext, replacement:=Replacetext, _ lookat:=xlPart, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

New Formula:

=@INDEX(INDEX(_Unit_Qty,,11),MATCH(1,($C$54=@_Product6N)*($C55=@_OptionXXX),0))

Note that an @ appears at the very beginning, and in front of the named ranges _Product6N and _OptionXXX. Also note it does not appear in front the name named range _Unit_Qty which was part of my .Replace within the VBA code.

Removing the @'s from in front of the named ranges then allows the formula to work.

Any suggestions?

Edit:

I recorded a macro performing this function. It recorded an argument I didn't have in my .Replace method.

Adding the following prevented the @'s from being added

FormulaVersion:=xlReplaceFormula2

l'll leave this up in case anyone can offer an explanation

Edit 2: 5 months ago this question was posted in this subreddit too: https://www.reddit.com/r/excel/comments/f97m8p/new_parameter_in_rangereplace_method/

To date there are still no official Microsoft pages explaining this argument

— 0