Բաց թողնել հիմնական բովանդակությունը

 Ինչպե՞ս կիրառել կոճակը Excel- ում հատուկ բջիջները մաքրելու համար:

Հեղինակ՝ Սյաոյանգ Վերջին փոփոխությունը՝ 2020-11-05

Սովորաբար, դուք կարող եք պահել այն Ctrl ստեղն ՝ բազմաթիվ հատուկ բջիջներ ընտրելու համար, և այնուհետև մաքրելու բջիջների պարունակությունը, որքան անհրաժեշտ է: Եթե ​​ձեզ միշտ անհրաժեշտ է ժամանակ առ ժամանակ մաքրել այս հատուկ բջիջները, կարող եք ստեղծել հստակ կոճակ, որպեսզի դրանք մաքրվեն միայն մեկ կտտոցով: Այս հոդվածում ես կխոսեմ այն ​​մասին, թե ինչպես ստեղծել հստակ բոլոր կոճակը ՝ բջիջների որոշ հատուկ պարունակությունը մաքրելու համար:

Կիրառեք կոճակ ՝ VBA կոդով բջջի որոշակի պարունակությունը մաքրելու համար


նետ կապույտ աջ պղպջակ Կիրառեք կոճակ ՝ VBA կոդով բջջի որոշակի պարունակությունը մաքրելու համար

Նախ, դուք պետք է ստեղծեք ձևի կոճակ, ապա կիրառեք կոդ, վերջապես, կապեք կոդը ձևի կոճակի հետ: Խնդրում ենք անել հետևյալը.

1: Սեղմեք Տեղադրել > Ձեւավորում > Ուղղանկյուններ ուղղանկյան ձևը ընտրելու համար, ապա մկնիկը քարշ տալով ուղղանկյան կոճակը թերթիկի ցանկացած կետում նկարելու համար, որքան անհրաժեշտ է, տե՛ս

doc կոճակը մաքրել բջիջները 1

2, Դրանից հետո մուտքագրեք տեքստը և ձևավորեք ձևի կոճակը, որքան ձեզ հարկավոր է, տե՛ս նկարը.

doc կոճակը մաքրել բջիջները 2

3, Եվ ապա պետք է տեղադրեք VBA կոդը, պահեք կոճակը ALT + F11 բացել ստեղները Microsoft Visual Basic հավելվածների համար պատուհան Սեղմել Տեղադրել > Մոդուլներ, և տեղադրեք հետևյալ կոդը Մոդուլներ Պատուհանը:

VBA կոդ. Մաքրել բջիջների պարունակությունը հատուկ բջիջներից.

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

ՆշումՎերոհիշյալ ծածկագրում. A2, A5 նշեք, որ այն կմաքրի բջիջները տիրույթում A2: A5, ոչ միայն երկու բջիջները առանձին-առանձին, կարող եք ավելացնել բազմակի տիրույթներ, ինչպիսիք են Range («B8», «B12»): Պարզ է սցենարը ծածկագրի մեջ `մաքրելու համար:

4, Դրանից հետո պահեք և փակեք ծածկագրի պատուհանը, ապա կոդը կապեք ձևի կոճակի հետ, աջ կտտացրեք կոճակին և ընտրեք Նշանակեք մակրոԷ, ապա Նշանակեք մակրո երկխոսության տուփ, ընտրեք Հեղինակներ կոդային անվանումը ՝ Մակրո անուն ցուցակի տուփը և կտտացրեք OK այս երկխոսությունից դուրս գալու կոճակը: Տեսեք,

doc կոճակը մաքրել բջիջները 3

5, Եվ հիմա, երբ կտտացնում ես Մաքրել բոլորը կոճակը, ձեր կողմից սահմանված հատուկ բջիջները միանգամից մաքրվում են, տես նկարի նկարը.

doc կոճակը մաքրել բջիջները 4

Գրասենյակի արտադրողականության լավագույն գործիքները

🤖 Kutools AI օգնականՀեղափոխություն կատարել տվյալների վերլուծության հիման վրա՝ Խելացի կատարում   |  Ստեղծեք ծածկագիր  |  Ստեղծեք հատուկ բանաձևեր  |  Վերլուծել տվյալները և ստեղծել գծապատկերներ  |  Invoke Kutools-ի գործառույթները...
Հանրաճանաչ հատկություններ: Գտեք, ընդգծեք կամ նույնականացրեք կրկնօրինակները   |  Deleteնջել դատարկ շարքերը   |  Միավորել սյունակները կամ բջիջները՝ առանց տվյալների կորստի   |   Կլոր առանց բանաձևի ...
Super Փնտրել: Բազմաթիվ չափանիշների VLookup    Բազմակի արժեք VLookup  |   VLookup բազմաթիվ թերթերում   |   Fuzzy Փնտրել ....
Ընդլայնված բացվող ցուցակ: Արագ ստեղծեք բացվող ցուցակը   |  Կախված բացվող ցուցակ   |  Բազմակի ընտրություն Drop Down ցուցակ ....
Սյունակի կառավարիչ: Ավելացրեք որոշակի քանակությամբ սյունակներ  |  Տեղափոխել սյունակները  |  Փոխարկել թաքնված սյունակների տեսանելիության կարգավիճակը  |  Համեմատեք միջակայքերը և սյունակները ...
Առանձնահատկություններ: Ցանցի կենտրոնացում   |  Դիզայնի տեսք   |   Մեծ Formula Bar    Աշխատանքային գրքույկի և թերթիկների կառավարիչ   |  Ռեսուրսների գրադարան (Ավտոմատ տեքստ)   |  Ամսաթիվ ընտրող   |  Միավորել աշխատանքային թերթերը   |  Գաղտնագրել/գաղտնազերծել բջիջները    Ուղարկեք նամակներ ըստ ցանկի   |  Սուպեր զտիչ   |   Հատուկ զտիչ (զտել թավ/շեղ/շեղված...) ...
Լավագույն 15 գործիքների հավաքածու12 Տեքստ Գործիքներ (Ավելացրեք տեքստ, Հեռացնել նիշերը, ...)   |   50+ Աղյուսակ Տեսակներ (Գանտի աղյուսակը, ...)   |   40+ Գործնական Բանաձեւեր (Հաշվարկել տարիքը ՝ ելնելով ծննդյան տարեդարձից, ...)   |   19 միացում Գործիքներ (Տեղադրեք QR կոդ, Տեղադրեք նկար ուղուց, ...)   |   12 Փոխարկում Գործիքներ (Բառեր համարներ, Արտարժույթի փոխակերպումը, ...)   |   7 Միաձուլում և պառակտում Գործիքներ (Ընդլայնված կոմբինատ տողեր, Պառակտված բջիջներ, ...)   |   ... եւ ավելին

Լրացրեք ձեր Excel-ի հմտությունները Kutools-ի հետ Excel-ի համար և փորձեք արդյունավետությունը, ինչպես երբեք: Kutools-ը Excel-ի համար առաջարկում է ավելի քան 300 առաջադեմ առանձնահատկություններ՝ արտադրողականությունը բարձրացնելու և ժամանակ խնայելու համար:  Սեղմեք այստեղ՝ Ձեզ ամենաշատ անհրաժեշտ հատկանիշը ստանալու համար...

Նկարագրություն


Office Tab- ը Tabbed ինտերֆեյսը բերում է Office, և ձեր աշխատանքը շատ ավելի դյուրին դարձրեք

  • Միացնել ներդիրներով խմբագրումը և ընթերցումը Word, Excel, PowerPoint- ով, Հրատարակիչ, Access, Visio և Project:
  • Բացեք և ստեղծեք բազմաթիվ փաստաթղթեր նույն պատուհանի նոր ներդիրներում, այլ ոչ թե նոր պատուհաններում:
  • Բարձրացնում է ձեր արտադրողականությունը 50%-ով և նվազեցնում մկնիկի հարյուրավոր սեղմումները ձեզ համար ամեն օր:
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