VBA : Error using Range.Formula - vba

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?

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))"

Related

How to do If Error If Vlookup with validations in vba macros [duplicate]

as a continuation from another question, I'm trying to solve my problems inserting a formula via VBA on a macro.
Here's my code:
Range("F1").Select
ActiveCell.Formula = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))"
For some reason, and the code doesn't show any errors, when I try to run it I get:
Run-time error ("Application-defined or object-defined error")
Worth mentioning I'm using Excel 2003.
Hope I'll be able to find my answer with you guys! Thanks in advance.
VBA is US-EN centric, so using the .Formula the formulas must be with , instead of ;:
Range("F1").Formula = "=IF(C1=""LPPD"",""MIPRU"",IF(C1=""LPGR"",""DCT"",IF(OR(C1=""LPFL"",C1=""LPCR""),""LADOX"",IF(OR(C1=""LPPI"",C1=""LPSJ"",C1=""LPHR""),""NOTMA"",""ERRO""))))"
Or you can use .FormulaLocal
Range("F1").FormulaLocal = "=IF(C1=""LPPD"";""MIPRU"";IF(C1=""LPGR"";""DCT"";IF(OR(C1=""LPFL"";C1=""LPCR"");""LADOX"";IF(OR(C1=""LPPI"";C1=""LPSJ"";C1=""LPHR"");""NOTMA"";""ERRO""))))"

VBA Runtime Error '1004' when attempting to Insert Formula

I've figured out how to insert a formula into a range of cells and managed to make it work once. Unfortunately, I can't get it to work with this formula. Instead I get an
Application-defined or object-defined error.
Here's what I'm attempting to run.
Sheets("P&L").Select
Range("A1:A250").Select
Selection.FormulaR1C1 = "=IF(ISNUMBER(LEFT(RC[+1],4)*1),LEFT(RC[+1]4,4)*1,)"
Selection.Columns.AutoFit
I suspect it has something to do with the * acting as a wildcard. I've put it in block quotes, but that just gives another error.
Any help is appreciated.
You've got an extra 4 in that formula.
Selection.FormulaR1C1 = "=IF(ISNUMBER(LEFT(RC[+1],4)*1),LEFT(RC[+1],4)*1, text(,))"

Application-defined or object-defined error for formula

I'm trying to use the following code to input a formula but for some reason I get an application defined / object defined error for the 'iferror' formula I'm using.
ws_catalogue.Range("D3").Formula = "=IFERROR(INDEX('Test Input'!$E:$E,MATCH(CONCATENATE([#Actor],[#Entity],D$1),'Test Input'!$A:$A,0)),"""")"
ws_catalogue.Range("D3:N3").FillRight
ws_catalogue.Range("D3:N" & Total_cat).FillDown
Thanks in advance!

Run-time error 1004 WorksheetFunction.Sum

When using the below within powerpoint, I constantly get
Run-time error 1004 - Unable to get the Sum property of the WorksheetFunction class
Can anyone help?
TextBox10.Value = WorksheetFunction.Sum(Staff_Engagement_1.Value, Annual_Cost_To_Business_1.Value, Cost_To_Absence_1.Value, (-1) * TextBox11.Value)
You can't use worksheetfunction in PowerPoint. Since i'm assuming you're using a form by the TextBox10.Value, see How can I sum value in 8 textboxes to the a single textbox?

VBA Excel implement COUNTIF function

I am trying to implement a "COUNTIF()" function in my vba excel application. I know how to do this programatically but I want specifically to implement this as a formula so that later changes in the sheet will hold. This is the problematic line:
ActiveSheet.Cells(3, 20).FormulaR1C1 = "=COUNTIF(R11C7:R12C7;"">0"")"
It results in the following error:
Run-time error '1004': Application-defined or object-defined error
VBA defaults to US formatting unless otherwise specified - which you could do here using FormulaR1C1Local - so you need to use a comma separator, not a semicolon.