Vai al contenuto principale

 Come applicare un pulsante per cancellare celle specifiche in Excel?

Normalmente, puoi tenere il Ctrl tasto per selezionare più celle specifiche, quindi cancellare il contenuto della cella di cui hai bisogno. Se hai sempre bisogno di cancellare queste celle specifiche di tanto in tanto, puoi creare un pulsante di cancellazione per cancellarle con un solo clic. In questo articolo, parlerò di come creare un pulsante Cancella tutto per cancellare alcuni contenuti di celle specifici.

Applica un pulsante per cancellare il contenuto di celle specifiche con il codice VBA


freccia blu freccia destra Applica un pulsante per cancellare il contenuto di celle specifiche con il codice VBA

Innanzitutto, dovresti creare un pulsante forma, quindi applicare un codice, infine, legare il codice al pulsante forma. Si prega di fare quanto segue:

1. Clic inserire > Forme > Rettangoli per selezionare la forma Rettangolo, quindi trascina il mouse per disegnare un pulsante rettangolo in qualsiasi punto del foglio di cui hai bisogno, vedi screenshot:

pulsante doc cancella celle 1

2. Quindi inserisci il testo e formatta il pulsante forma come necessario, vedi screenshot:

pulsante doc cancella celle 2

3. E poi dovresti inserire il codice VBA, tieni premuto il tasto ALT + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra. Clic inserire > Modulie incolla il codice seguente nel file Moduli Finestra.

Codice VBA: cancella il contenuto delle celle da celle specifiche:

Sub Clearcells()
'Updateby Extendoffice
Range("A2", "A5").Clear
Range("C10", "D18").Clear
Range("B8", "B12").Clear
End Sub

Note:: Nel codice sopra: A2, A5 indicare che cancellerà le celle nell'intervallo A2: A5, non solo le due celle singolarmente, puoi aggiungere più intervalli, come Intervallo ("B8", "B12") Cancella script all'interno del codice da cancellare.

4. Quindi salvare e chiudere la finestra del codice, quindi collegare il codice al pulsante della forma, fare clic con il pulsante destro del mouse e selezionare Assegna macro, Nella Assegna macro finestra di dialogo, scegliere il Celle chiare nome in codice da Nome della macro casella di riepilogo e fare clic su OK per uscire da questa finestra di dialogo. Vedi screenshot:

pulsante doc cancella celle 3

5. E ora, quando fai clic su Cancella tutto pulsante, le celle specifiche che hai definito vengono cancellate contemporaneamente, vedi screenshot:

pulsante doc cancella celle 4

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 (70)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
very helpful. thanks so much
This comment was minimized by the moderator on the site
Hi there,

Used this, and it works like a charm.

Only problem is... my cells are different formats... Some are 0,000 some are 00,00€ and when I it CLEAR, the format goes with tue clear event.

How can I clear the cells but maintain the format of them?
This comment was minimized by the moderator on the site
Hello, David,
To keep the cell formatting when clearing the cell contents, please apply the below code:
Sub ClearCellsKeepFormat()
    'Update by Extendoffice
    'This version clears the contents but keeps the cell formatting intact.
    Range("A2:A5").ClearContents
    Range("C10:D18").ClearContents
    Range("B8:B12").ClearContents
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
It worked. Thanks a lot man 😄
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi how do you use this macro without interfering the data validation?
This comment was minimized by the moderator on the site
I wanted that the confirmation needed for clear button .....so that the data is not cleared by mistakenly press the "clear" tab

And i wanted to say thanks for your brilliant work....thanks a lot in advance....

wish you have a great day...
This comment was minimized by the moderator on the site
Hello,
I am using this on one spreadsheet, but on 3 separate tabs. Everything was working last time I had the workbook open but today it is giving me an error "Ambiguous name detected: Clearcells". Please help!
This comment was minimized by the moderator on the site
Hallo zusammen,
hab soweit alles gemacht zu gewiesen usw. Funktioniert auch aber sobald ich die Datei öffne funktioniert es nicht mehr und muss alles neu eingeben.

Vorab vielen Dank
This comment was minimized by the moderator on the site
Meinte, nach dem schließen und dann wieder öffne.
This comment was minimized by the moderator on the site
Hi. I am trying to use a toggle button to clear all cells of color and text, but only the cells that contain the word “event”. And then I’d like to use the same toggle button to add the color and the word “event” back onto the spreadsheet. Can this be done?
This comment was minimized by the moderator on the site
Hallo,

Hoe kan ik cellen in een range met een formule intact houden met bovenstaand script?

Mvg,

Nol
This comment was minimized by the moderator on the site
Hello, Nol,
Do you mean to keep the formula cells when clearing the cell contents? Could you explain your problem by using English?

Thank you!
This comment was minimized by the moderator on the site
Hi Skyyang,

Thats what I mean indeed

Regards,

Nol
This comment was minimized by the moderator on the site
Hi, Nol,,
Maybe the follwoing VBA code can help you:
Sub Clearcells()
Dim xStr As String
Dim xRgs, xRg, xRgA As Range
xStr = "A2:C3,A5:E16,F5:H10"
Set xRgs = Range(xStr)
For Each xRgA In xRgs.Areas
    For Each xRg In xRgA
        If Not xRg.HasFormula Then
            xRg.Clear
        End If
    Next
Next
End Sub


Please change the cell references to your need, and you should use the comma to separate the data range.
Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Thanks Skyyang, the script works like an charm! Keep up the good work
This comment was minimized by the moderator on the site
Can you help me find a code that would clear the contents of merged cells but keep the formatting as well as formulas?
Thank you
This comment was minimized by the moderator on the site
¡Hola! Este código es fantástico para mí: Sub Clearcells() Rango("A2", "A5").ClearContents Rango("C10", "D18").ClearContents Rango("B8", "B12").ClearContents End Sub
Sin embargo, quisiera que me indicarais, si sois tan amables, cómo puedo a la vez que borro el contenido de dichas celdas, que éstas no tuvieran ningún color de relleno, el estilo fuera el normal, sin negrita ni cursiva y la fuente fuera arial 10 . Muchísimas gracias de antemano!!
This comment was minimized by the moderator on the site
Bonjour, j'ai créé un classeur pour une compétition sportive, 2 feuilles, une pour les éliminatoires et une pour les parties finales, j'ai créé un bouton par feuilles pour effacer le contenu des cellules, je voudrais protéger ces boutons, ils ne doivent être utilisés qu'à la fin de la compétition.
Merci d'avance
Didier
This comment was minimized by the moderator on the site
Hello Didier,

How are you. You can create two buttons for the two worksheets, each button for each worksheet. Then you can save the workbook. You can decide which contents to be cleared in which worksheets. Have a nice day.

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