Board index » delphi » Deleting a row in Excel

Deleting a row in Excel

Hello,

A simple question. How do I delete rows from an excel worksheet.

I use the OLEContainer component in Delphi 5.

I tried the following procedure

procedure TForm_Excel.DeleteRow(FromRow, ToRow : Integer);
Var
  Selection : Variant;
begin
  Selection := Sheet.Rows[IntToStr(FromRow) +  ':' +
IntToStr(ToRow)].Select;
  Selection.Delete(xlUp);
end;

When I use this I get the error "Variant does not reference an automation
object".

I useally use the VB Help library to get the syntaxt for the Excel function
to implement it in Excel but this one doesn't work.

Please help.

Marcel Horsthuis

 

Re:Deleting a row in Excel


<<Marcel Horsthuis:
How do I delete rows from an excel worksheet.

Quote

 WS.Range['C3', 'C5'].EntireRow.Delete(xlUp);

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Deleting a row in Excel


for i := FromRow to ToRow do
  Sheet.Rows[i].Delete;

--
With best regards, Mike Shkolnik
EMail: mshkol...@scalabium.com
http://www.scalabium.com

"Marcel Horsthuis" <mar...@horsthouse.nl> ???Y/???Y ?????
???Y??: news:3e91306b@newsgroups.borland.com...

Quote
> Hello,

> A simple question. How do I delete rows from an excel worksheet.

> I use the OLEContainer component in Delphi 5.

> I tried the following procedure

> procedure TForm_Excel.DeleteRow(FromRow, ToRow : Integer);
> Var
>   Selection : Variant;
> begin
>   Selection := Sheet.Rows[IntToStr(FromRow) +  ':' +
> IntToStr(ToRow)].Select;
>   Selection.Delete(xlUp);
> end;

> When I use this I get the error "Variant does not reference an automation
> object".

> I useally use the VB Help library to get the syntaxt for the Excel
function
> to implement it in Excel but this one doesn't work.

> Please help.

> Marcel Horsthuis

Re:Deleting a row in Excel


Thank you Mike,

It's easy if you know how it works.

I wonder if there is a central documentation on this subject. I see a lot of
examples on the internet but no
comprehencive "How to" guide or should I stick to the VB Help file approach.

marcel

"Mike Shkolnik" <mshkolnik2...@ukr.net> schreef in bericht
news:3e914641@newsgroups.borland.com...

Quote
> for i := FromRow to ToRow do
>   Sheet.Rows[i].Delete;

> --
> With best regards, Mike Shkolnik
> EMail: mshkol...@scalabium.com
> http://www.scalabium.com

> "Marcel Horsthuis" <mar...@horsthouse.nl> ???Y/???Y ?????
> ???Y??: news:3e91306b@newsgroups.borland.com...
> > Hello,

> > A simple question. How do I delete rows from an excel worksheet.

> > I use the OLEContainer component in Delphi 5.

> > I tried the following procedure

> > procedure TForm_Excel.DeleteRow(FromRow, ToRow : Integer);
> > Var
> >   Selection : Variant;
> > begin
> >   Selection := Sheet.Rows[IntToStr(FromRow) +  ':' +
> > IntToStr(ToRow)].Select;
> >   Selection.Delete(xlUp);
> > end;

> > When I use this I get the error "Variant does not reference an
automation
> > object".

> > I useally use the VB Help library to get the syntaxt for the Excel
> function
> > to implement it in Excel but this one doesn't work.

> > Please help.

> > Marcel Horsthuis

Re:Deleting a row in Excel


Marcel,

best help is a gelp-file for VBA from MS Excel

Also very useful is to start a macro recording in MS Excel, to do everything
what you want to do from Delphi program but to do in MS Excel and see a
generated VB code in VB editor. After that you must translate it to Delphi
only

--
With best regards, Mike Shkolnik
EMail: mshkol...@scalabium.com
http://www.scalabium.com

"Marcel Horsthuis" <mar...@horsthouse.nl> ???Y/???Y ?????
???Y??: news:3e91713c$1@newsgroups.borland.com...

Quote
> Thank you Mike,

> It's easy if you know how it works.

> I wonder if there is a central documentation on this subject. I see a lot
of
> examples on the internet but no
> comprehencive "How to" guide or should I stick to the VB Help file
approach.

> marcel

> "Mike Shkolnik" <mshkolnik2...@ukr.net> schreef in bericht
> news:3e914641@newsgroups.borland.com...
> > for i := FromRow to ToRow do
> >   Sheet.Rows[i].Delete;

> > --
> > With best regards, Mike Shkolnik
> > EMail: mshkol...@scalabium.com
> > http://www.scalabium.com

> > "Marcel Horsthuis" <mar...@horsthouse.nl> ???Y/???Y ?????
> > ???Y??: news:3e91306b@newsgroups.borland.com...
> > > Hello,

> > > A simple question. How do I delete rows from an excel worksheet.

> > > I use the OLEContainer component in Delphi 5.

> > > I tried the following procedure

> > > procedure TForm_Excel.DeleteRow(FromRow, ToRow : Integer);
> > > Var
> > >   Selection : Variant;
> > > begin
> > >   Selection := Sheet.Rows[IntToStr(FromRow) +  ':' +
> > > IntToStr(ToRow)].Select;
> > >   Selection.Delete(xlUp);
> > > end;

> > > When I use this I get the error "Variant does not reference an
> automation
> > > object".

> > > I useally use the VB Help library to get the syntaxt for the Excel
> > function
> > > to implement it in Excel but this one doesn't work.

> > > Please help.

> > > Marcel Horsthuis

Other Threads