@ Sign Causing an Error

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
608
Office Version
  1. 365
Platform
  1. Windows
Hello,
I created a macro that pastes a formula into a cell. It should look like this:
=IFERROR(INDEX(Physical_Sample!$A$2:$A$17, MATCH(0,COUNTIF($AE$1:AE1,Physical_Sample!$A$2:$A$17), 0)),"")

What happens is Excel automatically adds the “@” sign in front of the second occurrence of the sheet tab name:
=IFERROR(INDEX(Physical_Sample!$A$2:$A$17, MATCH(0,COUNTIF($AE$1:AE1,@Physical_Sample!$A$2:$A$17), 0)),"")

With the @ sign, it doesn’t pull any results. If I remove the @ sign manually, it works fine.

Do I need to do use Substitute to get rid of the @ sign?


Any help is appreciated.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Can you post the line of code that inserts the formula.
 
Upvote 0
VBA Code:
'Add Formulas
With Worksheets("Notes")
.Range("AD2") = "=IFERROR(INDEX(Book_Sample!$B$2:$B$" & LastB2 & ",MATCH(0,COUNTIF($AD$1:AD1,Book_Sample!$B$2:$B$" & LastB2 & "),0)),"""")"
.Range("AE2") = "=IFERROR(INDEX(Physical_Sample!$A$2:$A$" & lastb3 & ",MATCH(0,COUNTIF($AE$1:AE1,Physical_Sample!$A$2:$A$" & lastb3 & "),0)),"""")"
.Range("AD2:AE2").Copy
.Range("AD3:AE10").PasteSpecial Paste:=xlFormulas
End With
VBA Code:
 
Upvote 0
Thanks for that, try
VBA Code:
With Worksheets("Notes")
   .Range("AD2:AD10").Formula2 = "=IFERROR(INDEX(Book_Sample!$B$2:$B$" & LastB2 & ",MATCH(0,COUNTIF($AD$1:AD1,Book_Sample!$B$2:$B$" & LastB2 & "),0)),"""")"
   .Range("AE2:AE10").Formula2 = "=IFERROR(INDEX(Physical_Sample!$A$2:$A$" & lastb3 & ",MATCH(0,COUNTIF($AE$1:AE1,Physical_Sample!$A$2:$A$" & lastb3 & "),0)),"""")"
End With
 
Upvote 0
Ok, I had to step out for an hour but will test as soon as I get back and let you know. Thanks for responding
 
Upvote 0
As you have dynamic array functions you could also use
VBA Code:
With Worksheets("Notes")
   .Range("AE2").Formula2 = "=unique(Book_Sample!H2:H" & lastb2 & ")"
   .Range("AE2").Formula2 = "=unique(Physical_Sample!$A$2:$A$" & lastb3 & ")"
End With
 
Upvote 0
Interesting.... The first solution worked perfectly. The second one (using Unique) worked almost as well. The only difference is it skipped a row after the first entry. I had that issue with my first formula using the countif but solved it by entering a zero in cell AE1 and AD1.

Thank you for the help
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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