View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Jimmy O Jimmy O is offline
external usenet poster
 
Posts: 8
Default Determining number of Ranges

Thank you Gary for the reply. The blocks of numbers could be in other Ranges
of cells, for example B3: D8. However, to get this to work, I may have to
designate the Ranges that contain the date and then use Union.

"Gary''s Student" wrote:

Sub CountAreas()
Range("A1:C7").Value = 9
Range("F9:I16").Value = 10
Range("A21:D25").Value = 12

Union(Range("A1:C7"), Range("F9:I16"), Range("A21:D25")).Select


x = Selection.Areas.Count
Range("A30").Value = x
Debug.Print x
End Sub

You code made one big range / area.
--
Gary''s Student - gsnu200771


"Jimmy O" wrote:

I'm new to VBA and I have a worksheet where I need to determine the number of
contiguous blocks of cells with data in them. There could be two to four
blocks. All of the blocks will be within Range A1:I25. I thought I could use
Areas.Count so I set up a test Sub with three blocks of cells. Here is the
sub:

Sub CountAreas()
Range("A1:C7").Value = 9
Range("F9:I16").Value = 10
Range("A21:D25").Value = 12
Range("A1:I25").Select
x = Selection.Areas.Count
Range("A30").Value = x
Debug.Print x
End Sub

The value of x is 1 when I run the sub. I thought it should be 3. Any help
on what I'm doing incorrectly would be apprciated.