473,698 Members | 2,023 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 16111
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
8557
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
35549
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 utility from my PythonWin (IDE from ActiveSTate),
2
2115
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 application, application will evaluate results of spreadsheet calculations and create new set of data and
6
6366
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 spreadsheet do not have headers for use as field names (it's my assumption that my table should have a...
3
11683
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 need to use as the tab name in the exported Excel
0
3232
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 columns a, b, c and data below it. Only data get updated weekly So basically I have to automate...
1
3118
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. Has anyone else had issues with this?
1
3040
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 to complete your request." Can somebody help me please.
0
1313
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 criteria that I need to be incorporated into the database named qryImport.
3
20834
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 xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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

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.