471,319 Members | 3,299 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

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_Range("A1", Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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 15844
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**********@Hotmail.com> wrote in message news:ui*************@TK2MSFTNGP12.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_Range("A1", Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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***************@TK2MSFTNGP12.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**********@Hotmail.com> wrote in message news:ui*************@TK2MSFTNGP12.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_Range("A1", Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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.Delete
Range(Cells(1, 1), Cells(99, ubound var)).EntireColumn.Delete

Denis


"Karl Richards" <kc**********@Hotmail.com> wrote in message news:eu**************@TK2MSFTNGP11.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***************@TK2MSFTNGP12.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**********@Hotmail.com> wrote in message news:ui*************@TK2MSFTNGP12.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_Range("A1", Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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*************@TK2MSFTNGP14.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.Delete
Range(Cells(1, 1), Cells(99, ubound var)).EntireColumn.Delete

Denis


"Karl Richards" <kc**********@Hotmail.com> wrote in message news:eu**************@TK2MSFTNGP11.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***************@TK2MSFTNGP12.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**********@Hotmail.com> wrote in message news:ui*************@TK2MSFTNGP12.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_Range("A1", Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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**********@Hotmail.com> wrote in message news:Od**************@tk2msftngp13.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*************@TK2MSFTNGP14.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.Delete
Range(Cells(1, 1), Cells(99, ubound var)).EntireColumn.Delete

Denis


"Karl Richards" <kc**********@Hotmail.com> wrote in message news:eu**************@TK2MSFTNGP11.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***************@TK2MSFTNGP12.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**********@Hotmail.com> wrote in message news:ui*************@TK2MSFTNGP12.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_Range("A1", Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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**********@Hotmail.com
<mailto:kc**********@Hotmail.com>> wrote in message
news:Od**************@tk2msftngp13.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.there.com>> wrote in message
news:Ok*************@TK2MSFTNGP14.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.Delete
Range(Cells(1, 1), Cells(99, ubound var)).EntireColumn.Delete

Denis

"Karl Richards" <kc**********@Hotmail.com
<mailto:kc**********@Hotmail.com>> wrote in message
news:eu**************@TK2MSFTNGP11.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.there.com>> wrote in message
news:%2***************@TK2MSFTNGP12.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**********@Hotmail.com
<mailto:kc**********@Hotmail.com>> wrote in message
news:ui*************@TK2MSFTNGP12.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_Range("A1",
Type.Missing);
range = range.get_End(Excel.XlDirection.xlDown);
string downAddress = range.get_Address(false, false,
XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

range = oSheet.get_Range("A1",downAddress);
object[,] values = (object[,])range.Value2;

for (int i = 2; i < values.GetLength(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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Phil Powell | last post: by
13 posts views Thread by Allison Bailey | last post: by
1 post views Thread by Bill Atkins | last post: by

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.