J'ai une list de noms qui ont été exportés d'une autre database vers Excel. Les noms dans la list qui sont intéressants sont mis en évidence dans la police rouge. Je voudrais un moyen de le countr, c'est-à-dire que John Smith apparaît 5 fois au total dans une colonne, mais 3 des 5 fois, son nom apparaît souligné en police rouge. Je voudrais donc voir combien de cas son nom apparaît rouge.
Je sais comment searchr toutes les occurrences de son nom, par exemple = COUNTIF (A1: A100, "John Smith")
J'ai également aidé à créer une fonction VB qui count toutes les valeurs qui sont rouges (= SumRed) (une fois que l'indice de couleur est spécifié) dans une feuille de calcul en utilisant ceci:
Function SumRed(MyRange As Range) SumRed = 0 For Each cell In MyRange If cell.Font.Color = 255 Then SumRed = SumRed + cell.Value End If Next cell End Function
Je ne peux pas find un moyen de combiner les deux conditions de comptage. Toute aide serait très appréciée!
Vous n'avez pas besoin de VBA pour cela, mais encore si vous voulez VBA Solution, vous pouvez suivre les deux autres réponses. 🙂
Nous pouvons utiliser la formule Excel pour find la couleur de police d'une cellule. Voir cet exemple.
Nous utiliserons des macros XL4.
FontColor
=GET.CELL(24,OFFSET(INDIRECT("RC",FALSE),0,-1))
To =GET.CELL(24,OFFSET(INDIRECT("RC",FALSE),0,-1))
et click OK Explication de la formule
La syntaxe est
GET.CELL(type_num, reference) Type_num is a number that specifies what type of cell information you want. reference is the cell reference
GET.CELL (type_num, reference)GET.CELL(type_num, reference) Type_num is a number that specifies what type of cell information you want. reference is the cell reference
Type_num est un numéro qui spécifie quel type d'information de cellule vous voulez.GET.CELL(type_num, reference) Type_num is a number that specifies what type of cell information you want. reference is the cell reference
Dans la formule ci-dessus, le numéro 24
vous donne la couleur de la police du premier caractère dans la cellule, en tant que numéro dans la plage de 1 à 56. Si la couleur de la police est automatique, returnne 0. Et par conséquent, l'inconvénient. Assurez-vous que la couleur entière de la police est rouge. Nous aurions pu utiliser 64, mais cela ne fonctionne pas correctement.
OFFSET(INDIRECT("RC",FALSE),0,-1)
réfère à la cellule immédiate à gauche.
Entrez maintenant cette formule dans une cellule =IF(AND(Fontcolor=3,B1="John Smith"),1,0)
et copyz-le.
Remarque : la formule doit être saisie à droite de la cellule qui contient le text.
Screenshot
EDIT (10/12/2013)
Pour countr les cellules avec une contre-couleur spécifique, voir CE lien
Je pense que vous êtes presque là, mais cela mérite une autre fonction @user m'a parié à la ligne de punch 🙁
Function CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
Fonction CoundRedAndText (MyRange As Range, Mytext en tant que string) aussi longtimeFunction CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
CoundRedAndText = 0Function CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
Pour chaque cellule dans MyRangeFunction CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
Si cell.Font.Color = 255 et cell.value comme MyText ThenFunction CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
CoundRedAndText = CoundRedAndText + 1 'vous aviez cell.value mais ne sais pas pourquoi?Function CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
Cellule suivanteFunction CoundRedAndText(MyRange As Range, Mytext as ssortingng) as long CoundRedAndText = 0 For Each cell In MyRange If cell.Font.Color = 255 and cell.value like MyText Then CoundRedAndText = CoundRedAndText + 1 'you had cell.value but dont know why? End If Next cell End Function
Usage, =CountRedAndText(A1:A25, "John Smith")
For Each cell In Range("A1:A100") If cell.Font.Color = 255 And cell.Value = "John Smith" Then myCount = myCount + 1 End If Next
Pour chaque cellule en gamme ("A1: A100")For Each cell In Range("A1:A100") If cell.Font.Color = 255 And cell.Value = "John Smith" Then myCount = myCount + 1 End If Next
Si cell.Font.Color = 255 Et cell.Value = "John Smith" EnsuiteFor Each cell In Range("A1:A100") If cell.Font.Color = 255 And cell.Value = "John Smith" Then myCount = myCount + 1 End If Next
myCount = myCount + 1For Each cell In Range("A1:A100") If cell.Font.Color = 255 And cell.Value = "John Smith" Then myCount = myCount + 1 End If Next