0
votes

I am using Excel._Worksheet.UsedRange.Rows.Count property to get a count of populated rows. This worked up until I added protect worksheet. Now, my UsedRange returns a value equal to the length of the unlocked cells per column (100) instead of the number of populated cells per column (54). UsedRange returned 54 before I protected the sheet.

Now I get

NullReferenceException when I call ToString()

string columnValue = worksheet.Range[currentColumnString, currentColumnString].Value2.ToString();//currentColumnString = A55, Value2=null

This is because UsedRange.Rows.Count is wrong. How can I get row counts with a protected sheet?

1

1 Answers

0
votes

try Excel._Worksheet.Rows.Count... these http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.alloweditranges%28v=office.14%29.aspx can help to narrow down which Cells are protected.