I'm stumped and hoping for an answer to this weird issue.
In my VBA code, I'm creating a formula that access a column in my table called "Agent". (tbl_CSV_Import_Values[Agent]). The Agent column is in column 8 on my sheet. The table gets created/removed sometimes, and can have a different number of rows. After deleting the table, I recreate it, then run the VBA code to rewrite the formulas. For other formulas this works fine. But...
When I use the below code to stuff the formula into cell F3, it adds "@" to TWO of the "Agent" column References. For no reason I can discern. But it weirdly leaves one of the 3 Agent references alone. (See below)
My VBA:
ActiveSheet.Range("F3").Formula = "= ""Number of Agents: "" & SUM(IF(tbl_CSV_Import_Values[Agent]<>"""",1/COUNTIF(tbl_CSV_Import_Values[Agent], tbl_CSV_Import_Values[Agent]), 0))"
The Formula that get's place in cell F3 (generating an error due to those "@"s in front of Agent:
= "Number of Agents: " & SUM(IF(tbl_CSV_Import_Values[@Agent]<>"",1/COUNTIF(tbl_CSV_Import_Values[Agent], tbl_CSV_Import_Values[@Agent]), 0))
Of course, the formula fails... unless I simply delete those "@" signs from the formula manually. (The excel error says "A value used in the formula is a wrong data type".) With the two @'s deleted, the formula immediately works fine.
Does anyone have any idea why Excel is deciding to whack my column references (and only 2 of the 3?!) like that, and what I can do to stop it?
-Daniel