0

The cell is not filled with the formula, but a "FALSE" is written in there. Any ideas how to change that, so that the formula is displayed correctly? No error message though..

'code
q = 1
Do Until q = 10
   q = q + 1
   If Cells(q, 4).HasFormula Then
   Else
     If IsEmpty(Cells(q, 4)) Then
     Cells(q, 4).Formula = Cells(q, 4).Formula = "=IFERROR(VLOOKUP(E" & q & ",Lagerplätze!A:B,2,FALSE),)"
     End If
   End If
Loop

'code

EDIT: updated code

Thanks a lot!

9
  • What do you mean with "it isn't working properly"? Does it throw an error? It doesn't do anything? It does something, but not what you expected? Commented Sep 10, 2014 at 8:19
  • i hope it's clearer now Commented Sep 10, 2014 at 8:22
  • can you type the exact formula that you are trying to put. I mean how would you have entered in an Excel Cell Commented Sep 10, 2014 at 8:22
  • done that, look at the edit Commented Sep 10, 2014 at 8:27
  • Your VBA is referencing D but your excel formula is referencing E? Commented Sep 10, 2014 at 8:29

2 Answers 2

1

you need to use the & character to concatenate the formula's text with the q variable

 Cells(q, 4).Formula = "=IF(ISNA(VLOOKUP(D" & q & ";Lagerplätze!A:B;2;FALSE));"""";VLOOKUP(D" & q & ";Lagerplätze!A:B;2;FALSE))"

Edit: Added missing closing bracket.

Sign up to request clarification or add additional context in comments.

4 Comments

@SiddharthRout ... and I even know what Lagerplätze is without consulting a dictionary :-))
@KaChiing: Replace "D" with "E"
thanks for the hint, but it still tells me I got an objectrelated error
The IF statement is missing a closing bracket. It did in your original code and I did not catch it, because I was distracted by the missing & operator.
0

The .Formula property requires you to use US regional settings, so:

Cells(q, 5).Formula = "=IF(ISNA(VLOOKUP(E" & q & ",Lagerplätze!A:B,2,FALSE)),"""",VLOOKUP(E" & q & ",Lagerplätze!A:B,2,FALSE)"

Also, if you're using Excel 2007 or later, I'd suggest IFERROR:

Cells(q, 5).Formula = "=IFERROR(VLOOKUP(E" & q & ",Lagerplätze!A:B,2,FALSE),"""")

4 Comments

thanks, that was definitely one of the mistakes! but still, the cell isn't showing the formula like it's supposed to, but only a "FALSE"..
Just noticed you are putting the formula in column E, but you're also looking up column E. You can't do that - it creates a circular reference.
thats not the problem, it is supposed to fill D, by looking up column E. typo; i updated the code
You adjusted the code wrongly and doubled up the Cells(q, 4).Formula = part!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.