Microsoft Office Forums Count range cells eliminating merge cells

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2010, 12:40 AM
danbenedek danbenedek is offline Count range cells eliminating merge cells Windows XP Count range cells eliminating merge cells Office 2003
Novice
Count range cells eliminating merge cells
 
Join Date: Jan 2010
Posts: 3
danbenedek is on a distinguished road
Default Count range cells eliminating merge cells

I have created a method to count the number of cells in a range taking into consideration that merged cell are counted as one cell.
Here is the method
private static int getRangeCount(Range Target)
{
if (Target == null)
return 0;
if (Target.Cells == null)
return 0;
if (Target.Cells.Count <= 1)
return Target.Cells.Count;
int count = 0;
foreach (Range cell in Target)
{
if (cell.MergeCells != null && cell.MergeCells is bool && (bool)cell.MergeCells)
{
Range rng = (Range)cell.MergeArea[1, 1];
if (!Microsoft.Office.Tools.Excel.ExcelLocale1033Prox y.ReferenceEquals(cell, rng))
{


string str1 = WorkbookUtils.GetAddress(cell, XlReferenceStyle.xlA1);
string str2 = WorkbookUtils.GetAddress(rng, XlReferenceStyle.xlA1);
if (str1 == str2)
count++;
}
}
else
count++;
}
return count;
}
My problem now is that a user is using this method on a range with 8448 cells. Because the target is so big the method takes a very very very long time.
Is there a way to improve the above code?

Last edited by danbenedek; 06-15-2010 at 12:42 AM. Reason: code review
Reply With Quote
Reply

Tags
vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count range cells eliminating merge cells Cut and paste a range of cells and preserve formatting StarWeaver Excel 1 03-02-2010 01:41 PM
Count range cells eliminating merge cells Moving formula range multiple cells when moving sum over one cell FraserKitchell Excel 4 02-26-2010 10:38 AM
How to merge matching cells vertically? Odiseh Excel 1 01-02-2010 02:41 PM
Nested if formulat to merge cells cristi22 Excel 0 10-23-2006 08:28 AM
How to count cells containing data and meet certain criteria AdamNT Excel 1 08-11-2006 11:51 PM


All times are GMT -7. The time now is 07:18 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft