Preskoči na glavno vsebino

Kako skriti ali razkriti ukazni gumb na podlagi določene vrednosti celice v Excelu?

Recimo, da z ukaznim gumbom na svojem delovnem listu sprožite skript VBA. Kadar skript VBA v nekaterih primerih ni uporabljen, morate narediti ukazni gumb skrit, namesto da bi bil prikazan na delovnem listu. In ga spet prikažite, ko je potreben skript VBA. Ta članek govori o skrivanju ali prikazovanju ukaznega gumba, ki temelji na določeni vrednosti celice v Excelu. Naredite naslednje.

Skrijte ali razkrijte ukazni gumb na podlagi določene vrednosti celice s kodo VBA


Skrijte ali razkrijte ukazni gumb na podlagi določene vrednosti celice s kodo VBA

Spodnjo kodo VBA lahko zaženete, da skrijete ali razkrijete ukazni gumb na podlagi določene vrednosti celice v Excelu.

1. Z desno miškino tipko kliknite zavihek lista, ki vsebuje ukazni gumb, ki ga želite prikazati skriti, nato kliknite Ogled kode v meniju z desnim klikom.

2. V pojavnem oknu Microsoft Visual Basic za aplikacije okno, kopirajte in prilepite spodnjo kodo VBA v Koda okno.

Koda VBA: skrije ali razkrije ukazni gumb na podlagi določene vrednosti celice

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    If Cells(1, 1).Value <> "1" Then
        Me.CommandButton1.Visible = True
    Else
        Me.CommandButton1.Visible = False
    End If
    Application.ScreenUpdating = True
End Sub

Opombe: v kodi, Celice (1, 1), 1 in Ukazni gumb1 označite, da bo CommandButton1 skrit, ko celica A1 vsebuje številko 1, in prikazan, če celica A1 vsebuje druge vrednosti, razen številke 1. Glejte spodnji posnetek zaslona. In jih lahko spremenite glede na vaše potrebe.


Sorodni članki:

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 (14)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Cool idea. Pity it doesn't work :(
This comment was minimized by the moderator on the site
Der Code funktioniert wie er ist prima.
Ich würde nur gerne den Button bei jeder 0 und leeren Zelle ausblenden lassen. Irgendwie bekomme ich es nicht hin. Es funktioniert immer nur entweder oder. Könnten Sie mir bitte weiter helfen danke
This comment was minimized by the moderator on the site
Hi Christoph,

Sorry I don't understand what you mean. For clarity, please attach a sample file or a screenshot with your data and desired results.
This comment was minimized by the moderator on the site
Hola!
Alguien sabe como puedo hacer para que el boton comando aparezca o desaparezca segun información de otra hoja?
El ejemplo está muy bueno, pero las celdas son de la misma hoja donde esta el boton. Yo necesito ocultar un boton segun info de otra hoja.

Gracias!
This comment was minimized by the moderator on the site
Hi,
Suppose, the value used to display or hide the command button locates in A1 of Sheet1, and the comman button locates in Sheet2. Please open the Sheet1, right click the sheet tab and click View Code. In the opening Microsoft Visual Basic for Applications window, copy the following VBA code into the Sheet1 (Code) window, and then press the Alt + F11 keys to close it.
Note: Please change Cells(1, 1), "1" and "Sheet2" as you need.
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    If Cells(1, 1).Value <> "1" Then
        Sheets("Sheet2").CommandButton1.Visible = True
    Else
        Sheets("Sheet2").CommandButton1.Visible = False
    End If
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
hola, el codigo esta bien? es que no me funciona y ya intente varias cosas para que funcione y nana, ayuda por favor es que lo necesito para algo importante :c
This comment was minimized by the moderator on the site
For some reason after the button go from invisible back to visible, the button no longer works. If I alt + F11 into the code select the XXX() sub and run with F5 the code works for my macro. Why doesn't it work when i click the button anymore? in properties 'Enabled' is set to true
This comment was minimized by the moderator on the site
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Cells(1, 1).Value <> "1" Then
Me.Shapes("Button 1").Visible = True
Else
Me.Shapes("Button 1") End If
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hello

I am new to VBA, I have put this code into a new Excel. One CommnadButton, on Sheet1 but the code doesnt work.

Do I have to do anything before this?


Thanks in Advance
This comment was minimized by the moderator on the site
Use the ActiveX Control Button.
This comment was minimized by the moderator on the site
I've put this code in and entered my button name (Finish), referenced the reference cell (P11 - 16, 11) but every time I make a change to the reference cell (P11) I get a compile error and it highlights the ".Finish" section of the code, seemingly meaning the button name I entered "Finish" is not found on the worksheet. I've confirmed, both in the drop down area to the left of the formula bar and in the "define name" area on the Formula tab that my button name is, in fact, "Finish", but it still does not work.


Any help?
This comment was minimized by the moderator on the site
Hi Bryce,
I changed the button name to "Finish" in my worksheet, and it works well without any error displaying.
Do you mind testing the code in a new blank workbook?
Thank you for your comment.
This comment was minimized by the moderator on the site
hola que tal, tengo un boton con macro, que me devuelve a una hoja 'menu', pero no quiero que ese boton aparezca en la hoja menu como le puedo hacer?'


saludos.-
This comment was minimized by the moderator on the site
Hola Sebastia,

Dónde debería mostrarse?
- Uno es la hoja de menú
- El botón está integrado en una hoja diferente, no?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations