0

This code is supposed to get all rows in the range that I specify, and delete ONLY the rows with no cell DATA in them. It's actually deleting every row in the range though. Why?

Range range = _sheet.get_Range("A25:A542", Type.Missing);
range = range.EntireRow;
range.Delete(Type.Missing);
3
  • I'm sorry but I can see your code did exactly what it supposed to do.
    – Bolu
    Dec 9, 2010 at 14:35
  • you're not specifying which cells within the row you want to delete. You're selecting the entire row with range = range.EntireRow; and range.Delete(Type.Missing); deletes that entire row
    – user69820
    Dec 9, 2010 at 14:38
  • 1
    You should probably ask this question here - stackoverflow.com/questions/4398770/…. Dec 9, 2010 at 14:46

2 Answers 2

1

Type.Missing doesn't mean what you think it means. Type.Missing is a COM artefact - it just tells the Excel object that you're not providing that particular parameter. It's the kind of thing that's normally taken care of for you in VB.NET and VBA. C# 4.0 has support for optional parameters, which makes things much easier.

1

You do not check if any DATA exists, so the program deletes all rows from line 25 til line 542.

1
  • I thought Type.Missing check takes care of that in get_Range. How else would I do this?
    – slandau
    Dec 9, 2010 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.