Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA inserting unwanted quote marks!

Status
Not open for further replies.

CWalsh87

Technical User
Dec 15, 2010
16
0
0
Hi,

I need to insert a function into cells using VBA. For various reasons i need a variable in the function so i've used the following code:

For a = 1 to 10

activesheet.range("D1:D100").select
Selection.FormulaR1C1 = "=IF(ISERROR(SEARCH('Product Type'!D" & a & ",rc[1],1)),"""",'Product Type'!D" & a &")"

Next a

The forumula is inserted into the correct cells, but reads as follows:

=IF(ISERROR(SEARCH('Product Type'!'D10',F6,1)),"",'Product Type'!'D10')

As you can see the D10 has extra ' marks placed around it, therefore returning #NAME? error.

Has anyone any ideas??

Cheers
Chris
 
I've narrowed the problem down to the fact that i'm using R1C1 notation.

But i still don't know how i can stop the extra ' marks getting inserted
 
That's the exact problem I wrote in about at almost the exact time you wrote in. If there's any way you can construct your string to not use relative cell references then you can use ".formula" (without the R1C1). That's what I did.
 


Code:
for a = 1 to 10
  with Sheets("Product Type")
    activesheet.cells(a, "D").formula = "=IF(ISERROR(SEARCH('Product Type'!" & .cells(a, "D").address(false, false)& ",F6,1)),"""",'Product Type'!" & .cells(a, "D").address(false, false)& ")"
  end with
next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top