Advertisement
jsbsan

contarcolor

May 21st, 2014
4,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function CONTARCOLOR(CeldaColor As String, RangoSuma As String) As Double
  2. 'Ej  CONTARCOLOR("B5";"E2:F42") '' No olvidar las comillas , el primer parametro es la celda donde esta el color, la segunda es el rango donde procesamos y contamos sus coincidencias
  3. Dim oRango As Object
  4. Dim oCelda As Double
  5. Dim c As Integer
  6. Dim f As Integer
  7. Dim oCuenta as Integer
  8. oCuenta=0   'inicializamos variable
  9. oRango = ThisComponent.CurrentController.ActiveSheet
  10. oCelda = oRango.GetCellRangeByName(CeldaColor).CellBackColor
  11. oRango = oRango.GetCellRangeByName(RangoSuma)
  12. For c = 0 to oRango.Columns.Count - 1
  13.    For f = 0 to oRango.Rows.Count - 1
  14.       If    oRango.GetCellByPosition(c,f).CellBackColor = oCelda Then
  15.          oCuenta = oCuenta + 1
  16.       End If
  17.    Next
  18. Next
  19. CONTARCOLOR = oCuenta
  20. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement