Preskoči na glavno vsebino

 Kako uporabiti gumb za brisanje določenih celic v Excelu?

Običajno lahko držite tipko Ctrl tipko, da izberete več določenih celic in nato počistite vsebino celice, kot jo potrebujete. Če morate te posebne celice vedno občasno počistiti, lahko ustvarite gumb za brisanje, da jih počistite z enim samim klikom. V tem članku bom govoril o tem, kako ustvariti gumb za brisanje vseh za čiščenje nekaterih določenih vsebin celic.

Uporabite gumb za brisanje določene vsebine celice s kodo VBA


puščica modri desni mehurček Uporabite gumb za brisanje določene vsebine celice s kodo VBA

Najprej ustvarite gumb za obliko in nato uporabite kodo, končno jo privežite na gumb za obliko. Naredite naslednje:

1. Kliknite Vstavi > Oblike > Pravokotniki da izberete obliko pravokotnika in nato povlecite miško, da narišete gumb pravokotnika kjer koli na listu, kot želite, glejte posnetek zaslona:

gumb doc počisti celice 1

2. Nato vnesite besedilo in po potrebi oblikujte gumb za obliko, glejte posnetek zaslona:

gumb doc počisti celice 2

3. Nato vstavite kodo VBA, pridržite ALT + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno. Kliknite Vstavi > Moduliin prilepite naslednjo kodo v Moduli Okno.

Koda VBA: Izbriši vsebino celic iz določenih celic:

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

Opombe: V zgornji kodi: A2, A5 označite, da bo počistil celice v območju A2: A5, ne samo dveh celic posebej, lahko dodate več obsegov, na primer Območje ("B8", "B12"). Jasno skript v kodi za čiščenje.

4. Nato shranite in zaprite okno kode, nato kodo povežite z gumbom oblike, z desno miškino tipko kliknite gumb in izberite Dodeli makroV Dodeli makro v pogovornem oknu izberite Jasne celice kodno ime iz Ime makra in kliknite OK za izhod iz tega pogovornega okna. Oglejte si posnetek zaslona:

gumb doc počisti celice 3

5. In zdaj, ko kliknete Počisti vse gumba se določene celice, ki ste jih določili, naenkrat počistijo, glejte posnetek zaslona:

gumb doc počisti celice 4

Najboljša pisarniška orodja za produktivnost

🤖 Kutools AI Aide: Revolucionirajte analizo podatkov na podlagi: Inteligentna izvedba   |  Ustvari kodo  |  Ustvarite formule po meri  |  Analizirajte podatke in ustvarite grafikone  |  Prikličite funkcije Kutools...
Priljubljene funkcije: Poiščite, označite ali identificirajte dvojnike   |  Izbriši prazne vrstice   |  Združite stolpce ali celice brez izgube podatkov   |   Krog brez formule ...
Super iskanje: Več kriterijev VLookup    Multiple Value VLookup  |   VLookup na več listih   |   Nejasno iskanje ....
Napredni spustni seznam: Hitro ustvarite spustni seznam   |  Odvisni spustni seznam   |  Večkrat izberite spustni seznam ....
Upravitelj stolpcev: Dodajte določeno število stolpcev  |  Premakni stolpce  |  Preklop stanja vidnosti skritih stolpcev  |  Primerjaj obsege in stolpce ...
Predstavljene funkcije: Mrežni fokus   |  Pogled oblikovanja   |   Velika vrstica formule    Upravitelj delovnih zvezkov in listov   |  Knjižnica virov (Samodejno besedilo)   |  Izbirnik datuma   |  Združite delovne liste   |  Šifriranje/dešifriranje celic    Pošljite e-pošto po seznamu   |  Super filter   |   Poseben filter (filter krepko/ležeče/prečrtano ...) ...
15 najboljših kompletov orodij12 Besedilo Orodja (dodajanje besedila, Odstrani znake,...)   |   50 + Graf Vrste (Gantt Chart,...)   |   40+ Praktično Formule (Izračunajte starost glede na rojstni dan,...)   |   19 vstavljanje Orodja (Vstavite kodo QR, Vstavi sliko s poti,...)   |   12 Pretvorba Orodja (Številke v besede, Pretvorba valut,...)   |   7 Spoji in razdeli Orodja (Napredne kombinirane vrstice, Razdeljene celice,...)   |   ... in več

Napolnite svoje Excelove spretnosti s Kutools za Excel in izkusite učinkovitost kot še nikoli prej. Kutools za Excel ponuja več kot 300 naprednih funkcij za povečanje produktivnosti in prihranek časa.  Kliknite tukaj, če želite pridobiti funkcijo, ki jo najbolj potrebujete...

Opis


Kartica Office prinaša vmesnik z zavihki v Office in poenostavi vaše delo

  • Omogočite urejanje in branje z zavihki v Wordu, Excelu, PowerPointu, Publisher, Access, Visio in Project.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Poveča vašo produktivnost za 50%in vsak dan zmanjša na stotine klikov miške za vas!
Comments (73)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
is there a way to delete data from multiple sheets with just 1 button?
This comment was minimized by the moderator on the site
Hello, Roya,
To clear the specific cells in multiple sheet, please apply the following vba code:
Sub ClearMultipleRanges()
    Dim ws As Worksheet
    Dim sheetsToClear As Variant
    Dim cellRanges As Variant
    Dim range As Variant

    sheetsToClear = Array("Sheet1", "Sheet2", "Sheet3") ' Change the sheet names
    cellRanges = Array("A1:C3", "E1:E5", "G1:G10") ' Modify the cell ranges
    For Each ws In ThisWorkbook.Sheets
        If Not IsError(Application.Match(ws.Name, sheetsToClear, 0)) Then
            For Each range In cellRanges
                ws.range(range).ClearContents
            Next range
        End If
    Next ws
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
is there a way to delete data from multiple sheets with just 1 button?
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
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