We help IT Professionals succeed at work.

Excel formula SUMIFS not working when using Delphi

200 Views
Last Modified: 2018-03-15
When I try the program below I get
error  "OLE error 800A03EC"
When I put the formula
=SOMMEN.ALS(R[-8]K:R[-2]K;R[-8]K[-1]:R[-2]K[-1];">100";R[-8]K[-1]:R[-2]K[-1];"<200")
manualy in the Excel sheet on cell (11,2) everyting is ok.
In the attachment the test.xlsx file.

===================

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComObj, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var ExcelApp : variant;
begin
  ExcelApp:= CreateOleObject('Excel.Application');
  ExcelApp.DisplayAlerts := False;
  ExcelApp.Workbooks.Open('c:\users\myself\temp\test.xlsx');
  //"=SOMMEN.ALS" is Dutch version of "=SUMIFS"
  ExcelApp.ActiveWorkbook.WorkSheets[1].Cells(11,2):='=SOMMEN.ALS(R[-8]K:R[-2]K;R[-8]K[-1]:R[-2]K[-1];">100";R[-8]K[-1]:R[-2]K[-1];"<200")';
  ExcelApp.Visible:=True;
end;

end.
test.xlsx
Comment
Watch Question

Geert GOracle dba
CERTIFIED EXPERT
Top Expert 2009

Commented:
yeah, odd, i'm trying to figure this out too

this works:
ExcelApp.ActiveWorkbook.WorkSheets[1].Cells(11,2):='abc';

Open in new window

Author

Commented:
Also tryed "SUMIFS"  instead of "SOMMEN.ALS" but the same error
Oracle dba
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Yes!!
That does the trick!
What we learn from this is
1. Use the English version for the formulas so  "=SUMIFS" instead of "=SOMMEN.ALS" (dutch)
2. Use   ,  instead of  ;  to separate. (The formula creator in Excel uses ; to seperate.

I found that the variant ws is not neccesary.
Thanks,
Frans

Author

Commented:
Great help and saves me a lot of time.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.