메인 컨텐츠로 가기

Excel에서 지정된 셀 값을 기반으로 명령 단추를 숨기거나 숨기기를 해제하는 방법은 무엇입니까?

명령 단추를 사용하여 워크 시트에서 VBA 스크립트를 트리거한다고 가정합니다. 경우에 따라 VBA 스크립트를 사용하지 않는 경우 워크 시트에 표시하는 대신 명령 단추를 숨겨야합니다. 그리고 VBA 스크립트가 필요할 때 다시 표시하십시오. 이 기사에서는 Excel에서 지정된 셀 값을 기반으로 명령 단추를 숨기거나 표시하는 방법에 대해 설명합니다. 다음과 같이하십시오.

VBA 코드로 지정된 셀 값을 기반으로 명령 단추 숨기기 또는 숨기기 해제


VBA 코드로 지정된 셀 값을 기반으로 명령 단추 숨기기 또는 숨기기 해제

아래 VBA 코드를 실행하여 Excel에서 지정된 셀 값을 기반으로 명령 단추를 숨기거나 숨김 해제 할 수 있습니다.

1. 숨기기를 표시해야하는 명령 단추가 포함 된 시트 탭을 마우스 오른쪽 단추로 클릭 한 다음 코드보기 오른쪽 클릭 메뉴에서.

2. 팝업에서 응용 프로그램 용 Microsoft Visual Basic 창에서 아래 VBA 코드를 복사하여 붙여 넣으십시오. 암호 창.

VBA 코드 : 지정된 셀 값을 기반으로 명령 단추 숨기기 또는 숨기기 해제

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

주의 사항: 코드에서 세포 (1, 1), 1커맨드 버튼1 A1 셀에 숫자 1이 포함되어 있으면 CommandButton1이 숨겨지고 셀 A1에 숫자 1을 제외한 다른 값이 포함되어 있으면 표시됩니다. 아래 스크린 샷을 참조하십시오. 그리고 필요에 따라 변경할 수 있습니다.


관련 기사:

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
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