跳到主要內容

如何計算/求和Excel中的刪除線單元格?

在Excel中,我們總是格式化某些單元格的刪除線格式,以指示單元格值無用或無效,以便我們可以更準確地分析數據。 在本文中,我將討論如何使用Excel中的這些刪除線單元格在範圍內進行一些計算。

計算Excel中的刪除線單元格

在Excel中沒有刪除線單元格的計數

總和排除Excel中的刪除線單元格


箭頭藍色右氣泡 計算Excel中的刪除線單元格

如果要知道一個範圍中有多少具有刪除線格式的單元格,可以創建一個用戶定義函數,請執行以下步驟:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications窗口.

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊窗口.

VBA代碼:計算刪除線單元

Public Function CountStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If pRng.Font.Strikethrough Then
        xOut = xOut + 1
    End If
Next
CountStrike = xOut
End Function

3。 然後保存並關閉此代碼,並返回到工作表,然後輸入此公式 = CountStrike(A2:B14) 到空白單元格,請參見屏幕截圖:

文檔計數罷工-1

4.然後按 Enter 鍵,並且所有刪除線單元都已計數。 看截圖:

文檔計數罷工-1


箭頭藍色右氣泡 在Excel中沒有刪除線單元格的計數

但是,有時候,您可能只想計算除刪除線單元格以外的正常單元格的數量。 以下代碼可以為您提供幫助。

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications窗口.

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊窗口.

VBA代碼:無刪除線單元的計數

Public Function CountNoStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If Not pRng.Font.Strikethrough Then
        xOut = xOut + 1
    End If
Next
CountNoStrike = xOut
End Function

3。 然後保存並關閉此代碼,返回工作表,鍵入以下公式 =反擊(A2:B14) 放入空白單元格,然後按 Enter 鍵,那麼您將獲得所需的結果。

文檔計數罷工-1

備註:在上述公式中, A2:B14 是您要應用公式的範圍。


箭頭藍色右氣泡 總和排除Excel中的刪除線單元格

因為刪除線單元格未使用,所以在這裡,我只想對正常數字求和而不刪除線。 要解決此任務,您還需要一個用戶定義函數。

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications窗口.

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊窗口.

VBA代碼:總和排除刪除線單元

Public Function ExcStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If Not pRng.Font.Strikethrough Then
        xOut = xOut + pRng.Value
    End If
Next
ExcStrike = xOut
End Function

3。 然後保存並關閉此代碼,返回工作表,鍵入以下公式 = excstrike(B2:B14) 放入空白單元格,然後按 Enter 鍵,您將獲得所有數字的總和,而沒有刪除線單元格。 看截圖:

文檔計數罷工-1

備註:在上述公式中, B2:B14 是要對不帶刪除線格式的單元格求和的範圍。


相關文章:

如何在Excel中的一系列單元格中求和/計數粗體數字?

如何在Excel中根據背景色對單元格進行計數和求和?

如何根據Excel中的字體顏色對單元格進行計數/求和?

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I want to ignore the cell from count where both type of text strike and non strike available by VBA
This comment was minimized by the moderator on the site
Great! I found a little bug here. The result doesn't actualize by itself. When I do changes on the sheet, the number doesn't changes. How can I fix it? Thanks
This comment was minimized by the moderator on the site
Hi. Great code for ignoring strikethrough text whilst summing. But, is it possible to filter the data and get a subtotal which still sums without the strike through text? Thanks
This comment was minimized by the moderator on the site
This seems to round to whole numbers, and does not take into account the decimal places. For example, 1.35 + 1.00 would equal 2 instead of 2.35, but 1.50 + 1 would equal 3 instead of 2.50. How can you fix the code to add accurately?
This comment was minimized by the moderator on the site
[quote]This seems to round to whole numbers, and does not take into account the decimal places. For example, 1.35 + 1.00 would equal 2 instead of 2.35, but 1.50 + 1 would equal 3 instead of 2.50. How can you fix the code to add accurately?By Ari[/quote] ARI, just change the two words "Long" to "Double" in the formula. Here is the same formula above, with the correct Data Types to allow for values with decimal points: Public Function ExcStrike(pWorkRng As Range) As Double 'Update 20161107_IITCSglobal.com Application.Volatile Dim pRng As Range Dim xOut As Double xOut = 0 For Each pRng In pWorkRng If Not pRng.Font.Strikethrough Then xOut = xOut + pRng.Value End If Next ExcStrike = xOut End Function
This comment was minimized by the moderator on the site
Thank you very much for this information, it's extremely helpful, However, I'm having an issue using the VBA code: Sum exclude strikethrough cells.

It does not exclude the strikethrough cells in my table unless I manually perform a strikethrough then double click the cell for the code to work.

I'm using a table with a conditional format to shade and strikethrough the entire row when (Table Header called Sold) Column "W" cell contains a "Yes", then that row will have a strikethrough and grey color. The worksheet table is "InventoryItems" and is configured to calculated automatically, but the code is not being triggered to exclude the dollar amount when the cell contains the strikethrough. Could you advise what I might be doing wrong?
Thank you for your time and help.

There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations