Counting cells in a macro
Call the COUNTA worksheet function.
sectornum = Application.WorksheetFunction.CountA(Selection) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Tony" wrote in message ... If I have a group of cells selected and all I want to know is the number of cells that actually have data in them. How would I count them and set that to a variable? My worksheet has been filtered for non-blanks on this column, so when I use the following lines Range("d1").Select Range(Selection, Selection.End(xlDown)).Select sectornum = Selection.Count it selects all the cells down to the last one that has data in it, but then it returns the total number of cells selected. All I want to know is how many cells in this column have data in them, not a count that includes the blank ones. Thanks for the help! |
Counting cells in a macro
Thank you Chip that worked great...having issues with the site updating so
again i am sorry for the double post. "Chip Pearson" wrote: Call the COUNTA worksheet function. sectornum = Application.WorksheetFunction.CountA(Selection) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Tony" wrote in message ... If I have a group of cells selected and all I want to know is the number of cells that actually have data in them. How would I count them and set that to a variable? My worksheet has been filtered for non-blanks on this column, so when I use the following lines Range("d1").Select Range(Selection, Selection.End(xlDown)).Select sectornum = Selection.Count it selects all the cells down to the last one that has data in it, but then it returns the total number of cells selected. All I want to know is how many cells in this column have data in them, not a count that includes the blank ones. Thanks for the help! |
All times are GMT +1. The time now is 11:46 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com