2

I'm using this formula

ThisWorkbook.Sheets("Overview").Range(formrange).Formula = "=IF(OR(ISBLANK(B2);WEEKDAY(DATE($B$38;$B$37;B2);2)>5;DAY(EOMONTH(DATE($B$38;$B$37;B$3);0))<B2);0;IF(C2=""Y"";0,5;1))"

And am having the following error

Run-time error "1004"
Application-denied or object-defined error

Would you guys have an idea what that is?

8
  • 3
    Replace the semicolons with commas. Formula expects US syntax. Commented Mar 10, 2016 at 14:12
  • 2
    @chase no the 0,5 in american English would be 0.5, that will need to be changed also, though. So, good catch. Commented Mar 10, 2016 at 14:19
  • 2
    @ScottCraner Ah, interesting. Thank you for sharing Commented Mar 10, 2016 at 14:21
  • 1
    Weird how international editions of Excel use different function names and punctuation - but formulas entered in VBA still must be in the US format. Commented Mar 10, 2016 at 14:23
  • 1
    Sure, but it is a brutal violation of least surprise principle. It would be better if cell formulas were always in US format, or could be switched US/local with a click or something. Commented Mar 10, 2016 at 14:38

1 Answer 1

5

The Range.Formula property needs a formula string in the same format it would be entered into a cell on a computer with US regional settings. So for this example you need:

ThisWorkbook.Sheets("Overview").Range(formrange).Formula = "=IF(OR(ISBLANK(B2),WEEKDAY(DATE($B$38,$B$37,B2),2)>5,DAY(EOMONTH(DATE($B$38,$B$37,B$3),0))<B2),0,IF(C2=""Y"",0.5,1))"
Sign up to request clarification or add additional context in comments.

Comments

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.