View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Working with 2 range but wont work with 3

It happens that Cimjet formulated :
Hi Everyone
This is working ok but if I add one more range, it wont work.

Private Sub Worksheet_Change(ByVal Target As Range)
Set myrge = Worksheets("Calendar").Range("b6:af17", "b21:af32")
Range("R50") = Application.WorksheetFunction.CountIf(myrge, "V")
End Sub

This wont work:
Private Sub Worksheet_Change(ByVal Target As Range)
Set myrge = Worksheets("Calendar").Range("b6:af17", "b21:af32", "B36:af47")
Range("R50") = Application.WorksheetFunction.CountIf(myrge, "V")
End Sub
Regards
Cimjet


try...

Sub CountVs()
Dim sz As Variant, i As Integer, j As Long
Const sRngList As String = "$B$6:$AF$17,$B$21:$AF$32,$B$36:$AF$47"

For Each sz In Split(sRngList, ",")
j = j + Application.WorksheetFunction.CountIf(Range(sz), "V")
Next
Debug.Print j
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc