[算表] 以顏色為依據統計個數

看板Office作者 (龍魂不滅)時間15年前 (2010/09/30 15:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
軟體: Office Excel 版本: 2003 昨天有貼一篇問題,經過一番查詢後,終於找到答案 不過是使用巨集的方式,要注意的是在別台電腦由於未設定巨集 可能在別台電腦開啟時會出現警告 由於巨集不能即時計算,所以當有變化時須按F9來更新結果 算班表的時候還不錯用,提共給大家參考 ========== 1.以填充格顏色統計個數 Alt+F11開啟巨集編輯器,點選 插入->模組,輸入以下內容 Function CountByColor(Ref_color As Range, CountRange As Range) Application.Volatile Dim iCol As Integer Dim rCell As Range iCol = Ref_color.Interior.ColorIndex For Each rCell In CountRange If iCol = rCell.Interior.ColorIndex Then CountByColor = CountByColor + 1 End If Next rCell End Function 關閉巨集編輯器,在欲計算儲存格寫入以下公式 公式=CountByColor(A1,A3:S3) 其中A1為參照單元格,A3:S3為範圍 (可隨意變化) 就是計算出 A3~S3 範圍中,與A1相同填充格顏色的個數 ┌─┬─┬─┬─┬─┐ │ │A│B│C│D│ ├─┼─┼─┼─┼─┤ │1│ │ │ │2 │ ├─┼─┼─┼─┼─┤ │2│ │ │ │1 │ ├─┼─┼─┼─┼─┤ │3│ │3 │ ├─┼─┼─┼─┼─┤ │4│ │ │ │0 │ └─┴─┴─┴─┴─┘ ========== 2.以字體顏色統計個數 Alt+F11開啟巨集編輯器,點選 插入->模組,輸入以下內容 Function colorcount(rng As Range, ang As Range) Dim a As Range, b As Integer For Each a In ang If a.Font.ColorIndex = rng.Font.ColorIndex Then b = b + 1 End If Next colorcount = b End Function 關閉巨集編輯器,在欲計算儲存格寫入以下公式 公式=colorcount(A1,A3:S3) 其中A1為參照單元格,A3:S3為範圍 (可隨意變化) 就是計算出 A3~S3 範圍中,與A1相同字體顏色的個數 可點選資料編輯列按Enter以更新數據 ┌─┬─┬─┬─┬─┐ │ │A│B│C│D│ ├─┼─┼─┼─┼─┤ │1│1 │1 │1 │2 │ ├─┼─┼─┼─┼─┤ │2│1 │1 │1 │1 │ ├─┼─┼─┼─┼─┤ │3│111 │3 │ ├─┼─┼─┼─┼─┤ │4│1 │1 │1 │0 │ └─┴─┴─┴─┴─┘ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.137.86.32
文章代碼(AID): #1Cf42lyr (Office)
文章代碼(AID): #1Cf42lyr (Office)