473,574 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete a Row in Excel Spreadsheet

I am attempting to delete duplicate rows in a spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1", Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false, XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() == values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.
Dec 8 '05 #1
6 16106
Check out this link http://msdn.microsoft.com/library/de...l/ExcelObj.asp . ANd you are looking for the clear cell info.

Cheers,

Denis
"Karl Richards" <kc**********@H otmail.com> wrote in message news:ui******** *****@TK2MSFTNG P12.phx.gbl...
I am attempting to delete duplicate rows in a spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1", Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false, XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() == values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.
Dec 8 '05 #2
I want to delete the entire row... I have a range of 1280 rows that I want to remove the duplicate rows... I'm not sure I understand how the "clear cell info" is going to help with that.
"Denis Dougall" <De***********@ here.there.com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Check out this link http://msdn.microsoft.com/library/de...l/ExcelObj.asp . ANd you are looking for the clear cell info.

Cheers,

Denis
"Karl Richards" <kc**********@H otmail.com> wrote in message news:ui******** *****@TK2MSFTNG P12.phx.gbl...
I am attempting to delete duplicate rows in a spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1", Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false, XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() == values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.
Dec 8 '05 #3
You can then iterate through and delete the empty cells/rows and preserve your formulae. However here is some delete row code.


Range(x,y ).EntireRow.Del ete
Range(Cells(1, 1), Cells(99, ubound var)).EntireCol umn.Delete

Denis


"Karl Richards" <kc**********@H otmail.com> wrote in message news:eu******** ******@TK2MSFTN GP11.phx.gbl...
I want to delete the entire row... I have a range of 1280 rows that I want to remove the duplicate rows... I'm not sure I understand how the "clear cell info" is going to help with that.
"Denis Dougall" <De***********@ here.there.com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Check out this link http://msdn.microsoft.com/library/de...l/ExcelObj.asp . ANd you are looking for the clear cell info.

Cheers,

Denis
"Karl Richards" <kc**********@H otmail.com> wrote in message news:ui******** *****@TK2MSFTNG P12.phx.gbl...
I am attempting to delete duplicate rows in a spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1", Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false, XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() == values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.
Dec 8 '05 #4
I've tried that, but I keep getting "'object' does not contain a definition for 'EntireRow'".
"Denis Dougall" <De***********@ here.there.com> wrote in message news:Ok******** *****@TK2MSFTNG P14.phx.gbl...
You can then iterate through and delete the empty cells/rows and preserve your formulae. However here is some delete row code.
Range(x,y ).EntireRow.Del ete
Range(Cells(1, 1), Cells(99, ubound var)).EntireCol umn.Delete

Denis


"Karl Richards" <kc**********@H otmail.com> wrote in message news:eu******** ******@TK2MSFTN GP11.phx.gbl...
I want to delete the entire row... I have a range of 1280 rows that I want to remove the duplicate rows... I'm not sure I understand how the "clear cell info" is going to help with that.
"Denis Dougall" <De***********@ here.there.com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Check out this link http://msdn.microsoft.com/library/de...l/ExcelObj.asp . ANd you are looking for the clear cell info.

Cheers,

Denis
"Karl Richards" <kc**********@H otmail.com> wrote in message news:ui******** *****@TK2MSFTNG P12.phx.gbl...
I am attempting to delete duplicate rows in a spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1", Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false, XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() == values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.
Dec 8 '05 #5
If you have the range defined then use ADO.

--

Derek Davis
dd******@gmail. com
"Karl Richards" <kc**********@H otmail.com> wrote in message news:Od******** ******@tk2msftn gp13.phx.gbl...
I've tried that, but I keep getting "'object' does not contain a definition for 'EntireRow'".
"Denis Dougall" <De***********@ here.there.com> wrote in message news:Ok******** *****@TK2MSFTNG P14.phx.gbl...
You can then iterate through and delete the empty cells/rows and preserve your formulae. However here is some delete row code.
Range(x,y ).EntireRow.Del ete
Range(Cells(1, 1), Cells(99, ubound var)).EntireCol umn.Delete

Denis


"Karl Richards" <kc**********@H otmail.com> wrote in message news:eu******** ******@TK2MSFTN GP11.phx.gbl...
I want to delete the entire row... I have a range of 1280 rows that I want to remove the duplicate rows... I'm not sure I understand how the "clear cell info" is going to help with that.
"Denis Dougall" <De***********@ here.there.com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Check out this link http://msdn.microsoft.com/library/de...l/ExcelObj.asp . ANd you are looking for the clear cell info.

Cheers,

Denis
"Karl Richards" <kc**********@H otmail.com> wrote in message news:ui******** *****@TK2MSFTNG P12.phx.gbl...
I am attempting to delete duplicate rows in a spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1", Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false, XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() == values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.
Dec 8 '05 #6
Using Excel Macro record to record your action while you delete the row.
One the row is delete check how VBA is code to fullfill this task.

Then try the samething from your C#.

carion1 wrote:
If you have the range defined then use ADO.

--

Derek Davis
dd******@gmail. com <mailto:dd***** *@gmail.com>

"Karl Richards" <kc**********@H otmail.com
<mailto:kc***** *****@Hotmail.c om>> wrote in message
news:Od******** ******@tk2msftn gp13.phx.gbl...
I've tried that, but I keep getting "'object' does not contain a
definition for 'EntireRow'".

"Denis Dougall" <De***********@ here.there.com
<mailto:De***** ******@here.the re.com>> wrote in message
news:Ok******** *****@TK2MSFTNG P14.phx.gbl...
You can then iterate through and delete the empty cells/rows and
preserve your formulae. However here is some delete row code.
Range(x,y ).EntireRow.Del ete
Range(Cells(1, 1), Cells(99, ubound var)).EntireCol umn.Delete

Denis

"Karl Richards" <kc**********@H otmail.com
<mailto:kc***** *****@Hotmail.c om>> wrote in message
news:eu******** ******@TK2MSFTN GP11.phx.gbl...
I want to delete the entire row... I have a range of 1280
rows that I want to remove the duplicate rows... I'm not
sure I understand how the "clear cell info" is going to help
with that.

"Denis Dougall" <De***********@ here.there.com
<mailto:De***** ******@here.the re.com>> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Check out this link
http://msdn.microsoft.com/library/de...l/ExcelObj.asp .
ANd you are looking for the clear cell info.

Cheers,

Denis

"Karl Richards" <kc**********@H otmail.com
<mailto:kc***** *****@Hotmail.c om>> wrote in message
news:ui******** *****@TK2MSFTNG P12.phx.gbl...
I am attempting to delete duplicate rows in a
spreadsheet using the Excel object.

Does anyone have any idea how to do this? I've
looked everywhere that I can find on the Web and
have not been able to find anything on it.

What I have so far is:
Excel.Range range = oSheet.get_Rang e("A1",
Type.Missing);
range = range.get_End(E xcel.XlDirectio n.xlDown);
string downAddress = range.get_Addre ss(false, false,
XlReferenceStyl e.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Rang e("A1",downAddr ess);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLengt h(0); i++)
{
if (values[i-1,1].ToString() ==
values[i,1].ToString())
{
// This is where I want to delete the row.
}

any help would be greatly appreciated.

Dec 9 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8545
by: Phil Powell | last post by:
What would one best recommend to parse an existing Excel spreadsheet (was done in Excel 97 or 2000 not sure to be honest)? I am looking for the most practical way of parsing an existing spreadsheet to place contents into a mySQL db. Thanx, Phil PS: can you use fopen() to read the contents and parse? The spreadsheet is on a remote site.
13
35515
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy...
2
2101
by: quadric | last post by:
Hi, I have an application that requires that Python initiate and mediate a live and iterative conversation between an external application (in which Python is embedded) and an external Excel spreadsheet. Python will have to pass info to the spreadsheet, spreadsheet will make calculations, Python will obtain results and pass back to...
6
6357
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be able to take all of the data from the second column (B) of each worksheet and append that raw data to an access table. The columns in the...
3
11677
by: Scott M. Lyon | last post by:
I'm trying to figure out a way to export data (actually the result of a Stored Procedure call from SQL Server) into a specified Excel spreadsheet format. Currently, I have the data read into a DataSet that consists of one DataTable. That DataTable has a specific name (for arguments purposes, let's say it's called "DataGrid"), that I...
0
3227
by: ssrirao | last post by:
There is an Excel Spreadsheet containing data, residing in an internet site. It’s very easy to Import data from a local Excel Spreadsheet into SQL Server Database Table using DTS. But in my case the Excel spreadsheet resides an internet site which has a static name (Example xyz.xls) but varying data inside it. The spreadsheet contains three...
1
3109
by: Bill Atkins | last post by:
I'd like to embed an Excel spreadsheet in my C# application. The information I've found on the Web suggests placing a Web Browser control on the form and navigating it to an Excel spreadsheet. When I try this, I get a dialog asking if I'd like to open or save the spreadsheet - the spreadsheet never appears embedded in the application. ...
1
3035
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet report. I always get when trying to test it " 500 Internal Server Error - The server encountered an internal error or misconfiguration and was unable...
0
1311
by: Maurita | last post by:
Hi All, hope someone can lead me in the right direction. I am in new territory and am unsure what to do after importing an Excel Spreadsheet into my database. 1. The same spreadsheet with new information will periodically be imported into the database into tblImport. 2. I've created a query to so as to separate out the three fields and...
3
20828
by: Will | last post by:
Can someone help with code to delete multiple columns from an excel spreadsheet? I know which columns I need to delete. The code below will delete a single column but I'm not sure how to delete multiple columns. I'm tried experimenting with Dim rg As Excel.Range = xlSheet.Columns("B, D, G, K, L") but no joy. Thanks in advance Dim...
0
8058
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7820
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5624
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3742
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2249
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1061
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.