Cells Within Range Failure?

B

Bob Zimski

I don't know why, but the compiler is protesting the second to last line and
I don't know why. What have I missed?

Thanks

For i = maxrows To 2 Step -1
FormulaStr =
"=IF(ISNA(VLOOKUP(cells(i,1),[NegsExceptions.xls]Sheet1!$A$1:$C$18,1,FALSE)),""x"",VLOOKUP(cells(i,1),[NegsExceptions.xls]Sheet1!$A$1:$C$18,1,FALSE))"
Range(Cells(i, 5)).Formula = FormulaStr
Next i
 
M

Mike H

Bob,

There was also an error in your Vlookup because you had
cells(i,1) inside the quotes it was treated as text and you wanted a
variable. try this instead

For i = maxrows To 2 Step -1
FormulaStr = "=IF(ISNA(VLOOKUP(" & Cells(i, 1).Address &
",[NegsExceptions.xls]Sheet1!$A$1:$C$18,1,FALSE)),""x"",VLOOKUP(" & Cells(i,
1).Address & ",[NegsExceptions.xls]Sheet1!$A$1:$C$18,1,FALSE))"
Cells(i, 5).Formula = FormulaStr
Next i


Mike
 
J

Jim Thomlinson

What you have will not produce a valid formula. In your string you have
cells(i,1)
which is not going to be evalueated to a value. It will be exactly what you
see.

"=IF(ISNA(VLOOKUP(" & cells(i,1) &
",[NegsExceptions.xls]Sheet1!$A$1:$C$18,1,FALSE)),""x"",VLOOKUP(" &
cells(i,1) & ",[NegsExceptions.xls]Sheet1!$A$1:$C$18,1,FALSE))"

Assuming all else to be correct
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top