[[20210729162937]] 『赤文字のみカウントしたい。』(tunayosi) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『赤文字のみカウントしたい。』(tunayosi)

商品の在庫状況を確認する表で、

売却済みは黒文字
売却前は赤文字

と、管理しています。

ただ、空白にも文字色指定が入っているセルが多く、カウントしても正確な数字が出ていないようです。

ネットで見つけた下記のVBAを利用しましたが、空白もカウントしてしまいます。
空白セルをカウントしない方法はないでしょうか?


Public Function CountColor(ByVal area As Range, ByVal colorCell As Range) As Long

Dim targetRange As Range
Dim wkCount As Long

wkCount = 0

For Each targetRange In area
If targetRange.Font.Color = colorCell.Font.Color
Then wkCount = wkCount + 1
End If
Next

CountColor = wkCount

End Function


< 使用 Excel:Excel2019、使用 OS:Windows10 >


 Public Function CountColor(ByVal r As Range, ByVal colorCell As Range) As Long
     Dim targetCell As Range
     Dim wkCount As Long

     For Each targetCell In r
         If Not IsEmpty(targetCell) Then
             If targetCell.Font.Color = colorCell.Font.Color Then
                 wkCount = wkCount + 1
             End If
         End If
     Next

     CountColor = wkCount
 End Function

(半平太) 2021/07/29(木) 17:40


半平太さん

ありがとうございます、無事希望通りになりました。
感謝です!!
(tunayosi) 2021/07/29(木) 18:05


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.