Vai al contenuto principale

Come contare / sommare le celle barrate in Excel?

In Excel, formatta sempre il barrato per alcune celle che indicano che i valori delle celle sono inutili o non validi, in modo da poter analizzare i dati in modo più accurato. In questo articolo, parlerò di come eseguire alcuni calcoli nell'intervallo con queste celle barrate in Excel.

Contare le celle barrate in Excel

Conta senza barrare le celle in Excel

La somma esclude le celle barrate in Excel


freccia blu freccia destra Contare le celle barrate in Excel

Se vuoi sapere quante celle con formato barrato in un intervallo, puoi creare una funzione definita dall'utente, esegui le seguenti operazioni:

1. Tieni premuto il ALT + F11 chiavi per aprire il Finestra di Microsoft Visual Basic, Applications Edition.

2. Clic inserire > Modulie incolla il codice seguente nel file Finestra del modulo.

Codice VBA: conta le celle barrate

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. Quindi salva e chiudi questo codice e torna al foglio di lavoro, quindi inserisci questa formula = CountStrike (A2: B14) su una cella vuota, vedi screenshot:

doc-count-strike-1

4. Quindi premere entrare chiave e tutte le celle barrate sono state contate. Vedi screenshot:

doc-count-strike-1


freccia blu freccia destra Conta senza barrare le celle in Excel

Ma, a volte, potresti voler contare solo il numero delle celle normali che escludono le celle barrate. Il codice seguente può aiutarti.

1. Tieni premuto il ALT + F11 chiavi per aprire il Finestra di Microsoft Visual Basic, Applications Edition.

2. Clic inserire > Modulie incolla il codice seguente nel file Finestra del modulo.

Codice VBA: conta senza celle barrate

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. Quindi salva e chiudi questo codice, torna al tuo foglio di lavoro, digita questa formula = countnostrike (A2: B14) in una cella vuota e premere entrare chiave, quindi otterrai il risultato di cui hai bisogno.

doc-count-strike-1

Note:: Nelle formule precedenti, A2: B14 è l'intervallo a cui vuoi applicare le formule.


freccia blu freccia destra La somma esclude le celle barrate in Excel

Poiché le celle barrate sono inutilizzate, qui voglio sommare solo i numeri normali senza i numeri barrati. Per risolvere questo compito, è necessaria anche una funzione definita dall'utente.

1. Tieni premuto il ALT + F11 chiavi per aprire il Finestra di Microsoft Visual Basic, Applications Edition.

2. Clic inserire > Modulie incolla il codice seguente nel file Finestra del modulo.

Codice VBA: la somma esclude le celle barrate

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. Quindi salva e chiudi questo codice, torna al tuo foglio di lavoro, digita questa formula = excstrike (B2: B14) in una cella vuota e premere entrare chiave e otterrai la somma di tutti i numeri senza le celle barrate. Vedi screenshot:

doc-count-strike-1

Note:: Nelle formule precedenti, B2: B14 è l'intervallo in cui desideri sommare le celle senza il formato barrato.


Articoli correlati:

Come sommare / contare i numeri in grassetto in un intervallo di celle in Excel?

Come contare e sommare le celle in base al colore di sfondo in Excel?

Come contare / sommare le celle in base ai colori dei caratteri in Excel?

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
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