By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Delete a Row in Excel Spreadsheet

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.