看板 Office 關於我們 聯絡資訊
軟體:EXCEL 版本:2010 因有同事需要 我協助寫了一個自訂函數 目的是取得不重複項目個數 Function NoDuplicateCount(範圍) '統計不重複個數 字串 = "^" For Each cell In 範圍 If InStr(字串, cell) = 0 Then 字串 = 字串 & "^" & cell.Value Next If 字串 = "^" Then NoDuplicateCount = 0: Exit Function NoDuplicateCount = Len(字串) - Len(Application.Substitute(字串, "^", "")) - 1 End Function 一開始還可順利運作 但資料一多發現就錯了 我用msgbox抓了一下 發現是因為 字串 在某處就停止了 我猜應該是VBA對於變數的容量已經到了極限 那請問類似的目的有何其他的解法呢?? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.98.114.28 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1548127373.A.705.html
soyoso: 設個變數累加,以工作表函數countif計數,為1時累加1 01/22 11:47
soyoso: 最後回傳該變數值 01/22 11:47
soyoso: 或以要用dictionary方式,不存在exists時寫入任一數字,存 01/22 12:05
soyoso: 在時改寫入個文字,最後工作表函數count該變數的項目集合 01/22 12:06
home0303: 謝謝 Countif的方式我可以理解 就用這個來解 01/22 12:51