View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Count Empty Cells in Range After Cells with Data

Unless you need to check that filled cells are contiguous:

Sub Getthecount()
Dim rng as Range, sh as Worksheet
for each sh in activeworkbook.Worksheets
if instr(1,sh.name,"rev",vbTextcompare) = 1 then
set rng = sh.Range("D8:D31")
sh.Range("M2").Value = rng.countblank(rng)
sh.Range("M1").Value = rng.count - rng.Countblank(rng)
endif
Next
end sub

Test on a copy of your workbook

You didn't say where to write the results, so I used M1 and M2. Adjust to fit

--
Regards,
Tom Ogilvy


"David" wrote:

I have a fixed range of cells (D8:D31) on over 100 sheets that I need to get
two things:
1. The count of cells with data (0) and
2. The count of empty cells AFTER the cells with data to D31.

Once data is started in any period, there should be no break in the data,
i.e. if sales start in D14 and the last cell with data is D24, all the cells
inbetween will also have data.

Depending on when sales start, there can be empty cells starting at D8 to
when the first sales for a period are entered (these are new locations added
during the year).

Maybe setting a new range based on the first cell that is greater than 0 to
D31, and then doing the count on that range. I have no idea how to code this.
I need to write the results to two cells, but think I can do that part, but
need to to the same thing for all worksheets beginning with REV. The names
would be like REV001, REV002, etc.

Any ideas would be appreciated.