Insert an advanced formula into a cell - vba

Using Excel 2016 I am struggling to get a formula pasted into a cell with VBA (where the VBA does a data import). I have two sheets: Rapport SNN and Data.
Sheets("Rapport SNN").[E4].Formula = "=SUMIFS(Data!S2:Data!S2000;Data!V2:Data!V2000;""BankAxept"";Data!M2:Data!M2000;C4)/100"
Just throws me a:
Run-time error '1004': Application-defined or object-defined error.
What do I do wrong?

You have semicolons when they should be commas.
WorkSheets("Rapport SNN").[E4].Formula = "=SUMIFS(Data!S2:Data!S2000,Data!V2:Data!V2000,""BankAxept"",Data!M2:Data!M2000,C4)/100"

Related

My VBA code does not work in Office 2007

I developed and tested some VBA code using Office 2013 and was working perfectly. BUT when I ran it on Office 2007, the code breaks at this line...
ActiveSheet.Range("D6").Value = "=" & Worksheets("Formula").Range("AlarmsStatusFormula").Value
the error msg I received was Run-time error 1004: Application-defined or object-defined error. D6 is part of the same table that contains a column called "Message".
AlarmStatusFormula contains this formula
IF(OR(ISNUMBER(SEARCH({"Recover"," NR"},[Message]))),"FOUND","")
Note the AlarmStatusFormula named range has the workbook scope.
Can it be something to do with the way Excel 2007 handles named ranges vs 2013?
Can you please help with this?
In Excel 2007 it should be TableName[Message] rather than just [Message]

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!

Implementing Excel formula in VBA

I have this Excel formula which I would like to implement via VBA, unfortunately it keeps yielding an error.
My Excel formula:
IF(isemptyornothing(A1:A50); ""; IF(ISNUMBER(VALUE(A1:A50)); VALUE(A1:A50); A1:A50))
My VBA attempt:
Range("B1:B50").Formula = _
"=IF(IsEmptyorNothing(A1:A50), "", IF(ISNUMBER(VALUE(A1:A50)), VALUE(A1:A50), A1:A50))"
This yields the following error:
"Run-time error '1004': Application-defined or object-defined error"
Being a novice in VBA, I am not sure what to do with this.
"" needs to be """"
Also the formula you show would need to be array entered, but you can simple do this:
Range("B1:B50").Formula = _
"=IF(IsEmptyorNothing(A1), """", IF(ISNUMBER(VALUE(A1)), VALUE(A1), A1))"
And Excel will put adjust the A1 as the formula is copied down, automatically.
This assumes that IsEmptyorNothing is a UDF, because no such formula exists in standard Excel.

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.