Help prevent "@" from being added to VBA written OFFSET formulas

braindiesel

Well-known Member
Joined
Mar 16, 2009
Messages
571
Office Version
  1. 365
  2. 2019
  3. 2010
Platform
  1. Windows
I have code writing a complex function... what the formula does is irrelevant...
ActiveCell.Formula = "=HOUR(SMALL((OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),1,COUNTIF($A$3:$A$" & myBot & ",F3),1))*(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),2,COUNTIF($A$3:$A$" & myBot & ",F3),1)=1),ROWS($G$3:G3)+COUNTBLANK(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),2,COUNTIF($A$3:$A$" & myBot & ",F3),1))))"

In the cell, the macro writes what I want but adds in two @ characters
=HOUR(SMALL((@OFFSET($A$2,MATCH(F3,$A$3:$A$12,0),1,COUNTIF($A$3:$A$12,F3),1))*(@OFFSET($A$2,MATCH(F3,$A$3:$A$12,0),2,COUNTIF($A$3:$A$12,F3),1)=1),ROWS($G$3:G3)+COUNTBLANK(OFFSET($A$2,MATCH(F3,$A$3:$A$12,0),2,COUNTIF($A$3:$A$12,F3),1))))

It results in a NUM! error.
When I remove the 2 added @ symbols, the formula works perfectly

How do I prevent Excel from breaking my formula
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
When I run your exact same code I do not get the "@" sign inserted. It works perfectly. I have never seen anything like that happen.

Is there any possibility of sharing your file?
 
Upvote 0
This is basically it... it is just a dummy sheet to help solve another persons question on this site and I ran into this @ nonsense.

Below s entire sheet and entire code... a work in progress

LocationTime
7/1/2015​
6/1/2015​
AAA
10:10​
1​
AAA
#NUM!​
AAA
0.423611​
AAA
1​
AAA
AAA
10:16​
1​
AAA
#NUM!​
0.427778​
AAA
1​
AAA
13:53​
1​
AAA
#NUM!​
0.578472​
AAA
1​
AAA
15:37​
1​
AAA
#NUM!​
0.650694​
AAA
1​
AAA
16:25​
1​
AAA
#NUM!​
0.684028​
AAA
1​
AAA
17:35​
1​
AAA
10​
0.732639​
BBB
0​
AAA
21:35​
1​
AAA
16​
0.899306​
BBB
0​
AAA
21:44​
1​
AAA
21​
0.905556​
BBB
BBB
14:03​
1​
#N/A​
BBB
BBB
14:13​
1​
#N/A​
AAA
VBA Code:
Sub summarizeIt()
    Range("A3").Select 'change F3 to your starting cell
    
    myBot = Range("A2").End(xlDown).Row
    myTarg = Range("A3").Value
    myNowCtr = Application.SumIf(Range("A3:C" & myBot), myTarg, Range("C3:C" & myBot))
    myThenCtr = Application.SumIf(Range("A3:C" & myBot), myTarg, Range("D3:D" & myBot))
    
    Range("F3").Resize(myNowCtr + myThenCtr, 1).Value = myTarg
    Range("G3").Select
    ActiveCell.Formula = "=HOUR(SMALL((OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),1,COUNTIF($A$3:$A$" & myBot & ",F3),1))*(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),2,COUNTIF($A$3:$A$" & myBot & ",F3),1)=1),ROWS($G$3:G3)+COUNTBLANK(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),2,COUNTIF($A$3:$A$" & myBot & ",F3),1))))"
        '=HOUR(SMALL((OFFSET(R2C1,MATCH(RC[-1],R3C1:R12C1,0),1,COUNTIF(R3C1:R12C1,RC[-1]),1))*(OFFSET(R2C1,MATCH(RC[-1],R3C1:R12C1,0),2,COUNTIF(R3C1:R12C1,RC[-1]),1)=1),ROWS(R3C7:RC)+COUNTBLANK(OFFSET(R2C1,MATCH(RC[-1],R3C1:R12C1,0),2,COUNTIF(R3C1:R12C1,RC[-1]),1))))"
    'HOUR(SMALL((OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),1,COUNTIF($A$3:$A$" & myBot & ",F3),1))*(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),2,COUNTIF($A$3:$A$" & myBot & ",F3),1)=1),ROWS($G$3:G3)+COUNTBLANK(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),2,COUNTIF($A$3:$A$" & myBot & ",F3),1))))
    Selection.Resize(myNowCtr, 1).Select
    Selection.FillDown
    ActiveCell.Offset(myNowCtr, 0).Select
    ActiveCell.Formula = "=HOUR(SMALL((OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),1,COUNTIF($A$3:$A$" & myBot & ",F3),1))*(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),3,COUNTIF($A$3:$A$" & myBot & ",F3),1)=1),ROWS($G$3:G3)+COUNTBLANK(OFFSET($A$2,MATCH(F3,$A$3:$A$" & myBot & ",0),3,COUNTIF($A$3:$A$" & myBot & ",F3),1))))"
    Selection.Resize(myThenCtr, 1).Select
    Selection.FillDown
    
End Sub
 
Upvote 0
@braindiesel see the previous post by Fluff (post number 4)

It works perfectly. I have never seen anything like that happen.
Hi 6StringJazzer, just for info...

You won't get the issue as you aren't using 365.

 
Upvote 0
One caveat to post#4, I think that formula2 only works if you have dynamic arrays.
 
Upvote 0
You won't get the issue as you aren't using 365.
I have access to 365, I will have to install it. I was not familiar with this feature. It seems that Microsoft is adding a bunch of marginally useful features in 365 to herd everybody into its subscription model.

The OP does not have his version in his profile so this did not occur to me. Thanks.
 
Upvote 0
You can update your account details to show which version of Excel you are using.
 
Upvote 0

Forum statistics

Threads
1,215,555
Messages
6,125,490
Members
449,234
Latest member
slzaleski

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