[問題] 自訂函數計算文字顏色

看板Office作者 (大茲)時間7年前 (2019/03/15 13:05), 7年前編輯推噓0(006)
留言6則, 2人參與, 7年前最新討論串1/1
軟體: Excel 版本:365 想要自訂一個函數來計算選取範圍中含目標顏色的儲存格數量 Function FontColorCount(rng_c As Range, cell_a As Range) Dim qty As Integer Dim cel As Range qty = 0 For Each cel In rng_c If cel.Font.ColorIndex = cell_a.Font.ColorIndex Then qty= qty + 1 FontColorCount = qty End If Next cel End Function 但是運行後好像發現公式只能計算出原有儲存格文字設定的顏色,若是用條件化格式改變字 https://m.imgur.com/a/KPK6Thc 希望版上各位前輩能指點一下怎麼調整語法 十分感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.137.112.145 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1552626343.A.FD4.html

03/15 14:42, 7年前 , 1F
如果可改程序sub的話,以range.displayformat來判斷
03/15 14:42, 1F
※ 編輯: al53796 (114.137.112.145), 03/15/2019 15:00:15

03/15 15:19, 7年前 , 2F
Hi S大 我有改成(Range).DisplayFormat.Font.Color 但是
03/15 15:19, 2F

03/15 15:19, 7年前 , 3F
跑出來結果顯示為 #VALUE! 好像還是有什麼錯誤
03/15 15:19, 3F

03/15 15:28, 7年前 , 4F
寫在function內嗎?如果是的話,會回傳錯誤值#value!
03/15 15:28, 4F

03/15 15:29, 7年前 , 5F
請寫於回文提到的sub內
03/15 15:29, 5F

03/15 15:38, 7年前 , 6F
喔喔 對 我是改在function... 來研究一下怎麼改sub @@
03/15 15:38, 6F
文章代碼(AID): #1SYpAd_K (Office)
文章代碼(AID): #1SYpAd_K (Office)