@ is showing up in formula through vba - need to stop it

Jim885

Well-known Member
Joined
Jul 8, 2012
Messages
663
I've spent some time researching this but haven't been able to come close to finding an answer. So maybe someone here can help.

My office is using Excel 365 in Windows 10

I ran the below lines of code, then the "@" sign is showing up as part of the formulas on the excel spreadsheet, and causing erroneous formula results.
I would like to prevent Excel 365 from doing this, or come up with a solution in vba to eliminate this from '@' appearing in the spreadsheet formula.

Hope someone can help.

The vba code I have:
ws2.Range("K2:K" & iRow).Formula = "=SUM(IF($D$2:$D2=D2,($H$2:$H2),0))"
ws2.Range("M2:M" & iRow).Formula = "=IFERROR(SUM(IF($D$2:$D2=D2,($H$2:$H2)/E2,0)),""-"")"

The formula I expected to appear in the cells;

=SUM(IF($D$2:$D2=D2,($H$2:$H2),0))
=IFERROR(SUM(IF($D$2:$D2=D2,($H$2:$H2)/E2,0)),"-")


The formula that appears in the cells and produces miscalculations;
=SUM(IF($D$2:$D2=@D2,($H$2:$H2),0))
=IFERROR(SUM(IF(@$D$2:$D2=D2,(@$H$2:$H2)/E2,0)),"-")


The first time this happened today, I got a quick "popup" that said this is new, and the @ would not affect the formula result ... But it has

Does anyone have an idea how to eliminate this @ problem from appearing in the formula?

Thanks.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Snag_1e9b090b.png
 
Upvote 0
reportedly people have been just ctrl H replacing any @'s with blank and getting formulas to work as intended
 
Upvote 0
Your formulae don't make sense. The main issue is that you're comparing a range with a value. E.g. by the time the formulae are copied to row 20 they say, in part, $D$2:$D20=D20. This returns an array of 19 values, the first 18 of which are FALSE and the last one is TRUE.
This is unlikely to be what you intended. More generally, most of each formula isn't actually doing anything useful. Consequently, they can be greatly simplified:
=SUM(IF($D$2:$D2=D2,($H$2:$H2),0)) is equivalent to =H2
=IFERROR(SUM(IF($D$2:$D2=D2,($H$2:$H2)/E2,0)),"-") is equivalent to =IFERROR(H2/E2,"-")
 
Upvote 0
=SUM(IF($D$2:$D2=D2,($H$2:$H2),0)) is equivalent to =H2
=IFERROR(SUM(IF($D$2:$D2=D2,($H$2:$H2)/E2,0)),"-") is equivalent to =IFERROR(H2/E2,"-")
@i_nth, If dealing with a single cell holding the formula the above is correct but what happens if you drag the formulas down? I get the below for the first formula (please note that the implicit operator doesn't show with the XL2BB app yet)...

Book1
DHKLM
1With implicitw/o impliciti_nth
233333
324744
4551255
5311341
6231673
7321862
83422104
93325133
102530125
113535185
Sheet1
Cell Formulas
RangeFormula
K2:K11K2=SUM(IF($D$2:$D2=D2,($H$2:$H2),0))
L2:L11L2=SUM(IF($D$2:$D2=D2,($H$2:$H2),0))
M2:M11M2=H2
 
Last edited:
Upvote 0
@Jim885, playing around with it if you put it in VBA as .FormulaArray rather than .Formula it won't put in the implicit operator but you will need to put it in a single cell and copy/paste or filldown rather than applying it to the whole range or use another method (like below, I use Column N just for testing).

VBA Code:
Sub Jim885()
Dim iRow As Long
iRow = 11
    With Sheets("Sheet1").Range("N2:N" & iRow)
        .Formula = "=SUM(IF($D$2:$D2=D2,($H$2:$H2),0))"
        .FormulaArray = .FormulaR1C1
    End With
End Sub
 
Last edited:
Upvote 0
Thank you all,
I will try each of the suggestions later tonight and report back. I have to test this on the work computer since I don't have 365 at home.
I'm also wondering if SUMIFS can be used instead of either formula.
 
Upvote 0
=SUMIF($D$2:$D2,D2,$H$2:$H2)
and
=IFERROR(SUMIF($D$2:$D2,D2,$H$2:$H2)/E2,0)
 
Upvote 0
fhqwgads,
In my original code, I had;
VBA Code:
        Range("M2:M" & iRow).Replace What:="@", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
to handle/remove the @ issue. (same as Ctrl +H). So thanks for thinking about that. I wanted to avoid the @ problem rather than deal with it.

RoryA,
Your approach worked. Thanks! Then I ended up switching some columns around.

Mark858,
Thanks for spending the time to work it out on a spreadsheet and code it as well. I like the switch you added ;
VBA Code:
  .FormulaArray = .FormulaR1C1
Very nice.

In the end, I switched some columns around in the spreadsheet and ended up using;
VBA Code:
    ws2.Range("K2:K" & iRow).Formula = "=SUMIFS(H$2:H2,$D$2:$D2,D2)"  
    ws2.Range("L2:L" & iRow).Formula = "=E2-K2" 
    ws2.Range("M2:M" & iRow).Formula = "=(SUMIFS($H$2:$H2,$D$2:$D2,$D2)/$E2)"

The code tallies matching values as rows are added to the spreadsheet,
 
Upvote 0
VBE313,
Thanks for the info. All I know is that I got the results I wanted/expected in the original array formula after I removed the "@" from the cells.
The "@" was throwing the original formula result way off.

I hope I never have to deal with the implicit operator. I like life without the @ operator.
Thanks to all.
 
Upvote 0

Forum statistics

Threads
1,222,125
Messages
6,164,112
Members
451,874
Latest member
Skullflame

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top