Ddavidfernandes
New Member
- Joined
- Jan 31, 2018
- Messages
- 1
Hi all,
for a given day, i need to count the cells with certain colors.
in VBA : to count color cell :
Function CountColorIf(rSample As Range, rArea As Range) As Long
Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long
lMatchColor = rSample.Interior.Color
For Each rAreaCell In rArea
If rAreaCell.Interior.Color = lMatchColor Then
lCounter = lCounter + 1
Next rAreaCell
CountColorIf = lCounter
End Function
in VBA : to find the column where the data is used
Function ConvertToLetter(iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
But the result from data is in TEXT (this give the column). I need help to find a way to use the result in the CountColorIf function.
thanks!
David.
for a given day, i need to count the cells with certain colors.
in VBA : to count color cell :
Function CountColorIf(rSample As Range, rArea As Range) As Long
Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long
lMatchColor = rSample.Interior.Color
For Each rAreaCell In rArea
If rAreaCell.Interior.Color = lMatchColor Then
lCounter = lCounter + 1
Next rAreaCell
CountColorIf = lCounter
End Function
in VBA : to find the column where the data is used
Function ConvertToLetter(iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
But the result from data is in TEXT (this give the column). I need help to find a way to use the result in the CountColorIf function.
thanks!
David.