A process to quickly detect whether there is data in a given worksheet or not, without actually looping through all of the rows/columns of the worksheet.
For my curre
I found the following solution, which is also instantaneous but I'm not sure how accurate it is... it has passed all my tests thus far.
Here it is for anyone who wants to know:
Worksheet sheet = (Worksheet)this.Application.ActiveSheet;
Range usedRange = sheet.UsedRange;
bool isUsed = (usedRange.Count > 1);
if (usedRange.Count == 1)
{
isUsed = (usedRange.Value2 != null) &&
(!string.IsNullOrEmpty(usedRange.Value2.ToString()));
}
if(isUsed)
{
// worksheet cells not empty
}
I suppose this is a lot simpler than blowing up the clipboard every time I do the check or counting all the non-empty cells in the worksheet. Thanks Mikael and Mike, I appreciate both your answers.