메인 컨텐츠로 가기

셀 값에 따라 시트 탭 색상을 변경하는 방법은 무엇입니까?

일반적으로 Excel에서 탭 색상을 쉽고 빠르게 변경할 수 있지만 워크 시트의 셀 값을 기반으로 탭 색상을 변경해 본 적이 있습니까? 이 작업에 관심이 있다면 Excel의 특정 셀 값을 기반으로 시트 탭의 색상을 지정하는 몇 가지 코드에 대해 설명하겠습니다.

VBA 코드로 셀 값을 기반으로 한 시트 탭 색상 변경

VBA 코드로 셀 값을 기반으로 여러 시트 탭 변경


화살표 블루 오른쪽 거품 VBA 코드로 셀 값을 기반으로 한 시트 탭 색상 변경

예를 들어, A1의 셀 값이 "TRUE"이면 현재 시트 탭 색상이 녹색이되고, A1의 텍스트가 "FALSE"이면 탭 색상이 빨간색이되고, 탭 색상은 파란색이됩니다. A1 셀의 값은 다음 스크린 샷에 표시된 다른 텍스트입니다.

값별 문서 컬러 시트 1

1. A1 셀의 데이터를 기반으로 색상을 변경하려는 시트 탭을 마우스 오른쪽 단추로 클릭 한 다음 코드보기 컨텍스트 메뉴에서.

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

VBA 코드 : 셀 값에 따라 하나의 시트 탭 색상을 변경합니다.

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    If Target.Address = "$A$1" Then
        Select Case Target.Value
        Case "False"
            Me.Tab.Color = vbRed
        Case "True"
            Me.Tab.Color = vbGreen
        Case Else
            Me.Tab.Color = vbBlue
        End Select
    End If
End Sub

값별 문서 컬러 시트 2

참고 : 위의 코드에서 A1 탭에 색상을 지정하려는 셀 참조입니다. "참된","거짓”는 필요한 텍스트이며 필요에 따라 변경할 수 있으며 필요에 따라 코드의 색상을 변경할 수 있습니다.

3. 그런 다음이 코드 창을 저장하고 닫습니다. 이제 A1 셀에 "True"라는 텍스트를 입력하면 현재 탭 색상이 녹색이되고 A1 셀에 "False"텍스트를 입력하면 탭 색상이 빨간색이됩니다. A1 셀에 다른 텍스트를 입력하면 탭 색상이 자동으로 파란색이됩니다.


화살표 블루 오른쪽 거품 VBA 코드로 셀 값을 기반으로 여러 시트 탭 변경

셀 값을 기반으로 여러 시트 탭 색상을 변경해야하는 경우 여기에 코드가 도움이 될 수 있습니다. 다음과 같이하십시오.

1. 누르고 ALT + F11 키를 눌러 응용 프로그램 용 Microsoft Visual Basic 창, 열린 창에서 두 번 클릭 이 워크북 아래 VBA 프로젝트 섹션, 그런 다음 아래 코드를 복사하여 빈 칸에 붙여 넣으십시오. 모듈:

VBA 코드 : 셀 값에 따라 여러 시트 탭 변경 :

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  'Updateby Extendoffice 20160930
  Select Case Sheets("Master").Range("A1").Value
         Case "KTE"
             Sheets("Sheet1").Tab.Color = vbRed
         Case "KTO"
             Sheets("Sheet2").Tab.Color = vbGreen
         Case "KTW"
             Sheets("Sheet3").Tab.Color = vbBlue
         End Select
End Sub

값별 문서 컬러 시트 3

참고 : 위의 코드에서 A1 마스터는 탭의 색상을 지정하려는 셀과 워크 시트입니다. Sheet1, Sheet2, Sheet3 탭의 색상을 지정할 워크 시트입니다. KTE, KTW, KTO 탭의 색상을 지정하려는 A1의 셀 값입니다. 필요에 따라 코드의 참조 및 색상을 변경할 수 있습니다.

2. 그런 다음이 코드 창을 저장하고 닫으십시오. 이제 Master sheet의 A1 셀에 KTE 텍스트를 입력하면 Sheet1 탭이 빨간색으로 표시되고 A1 셀에 KTO를 입력하면 Sheet2가 녹색으로 표시되고 A1 셀에 KTW를 입력하면 Sheet3이 파란색으로 표시됩니다. 스크린 샷 참조 :

값별 문서 컬러 시트 4

최고의 사무 생산성 도구

🤖 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 (28)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I want every tab to turn Red if G18 is greater than 100. Could someone help me write this code?
This comment was minimized by the moderator on the site
Hello, Lesa,

To modify the code so that when the value in G18 exceeds 100, the color of all worksheet tabs is set to red, you need to implement this functionality in the ThisWorkbook event, not in the Worksheet_Change event of a single worksheet.
1. Open the VBA editor (Alt + F11).
2. In the Project Explorer, find the ThisWorkbook object and double-click to open it.
3. Copy and paste the following code into the code window of ThisWorkbook:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Not Intersect(Target, Sh.Range("G18")) Is Nothing Then
        Dim ws As Worksheet
        If Sh.Range("G18").Value > 100 Then
            For Each ws In ThisWorkbook.Worksheets
                ws.Tab.Color = RGB(255, 0, 0)
            Next ws
        Else
            For Each ws In ThisWorkbook.Worksheets
                ws.Tab.ColorIndex = xlColorIndexNone
            Next ws
        End If
    End If
End Sub


Result:
If G18 > 100 in any sheet, it iterates through all the worksheets in the workbook, setting their tab color to red.
If the condition is not met, it resets the tab color of all worksheets to the default color.

Please have a try!
This comment was minimized by the moderator on the site
Hi,


I used this code:

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'Updateby Extendoffice 20160930
Select Case Sheets("Master").Range("A1").Value
Case "KTE"
Sheets("Sheet1").Tab.Color = vbRed
Case "KTO"
Sheets("Sheet2").Tab.Color = vbGreen
Case "KTW"
Sheets("Sheet3").Tab.Color = vbBlue
End Select
End Sub

The True, False or Else function works for me when I type it manually. However, I have a formula that displays True, False or Else as the result. This formula suddenly causes no response when changing the tab color. The formula is based on another sheet, is this a problem?
This comment was minimized by the moderator on the site
Hello Fabian,

Same problem here, have you found any solution to solve this problem ?

Thanks.
This comment was minimized by the moderator on the site
I have a workbook that has 350+ tabs in it. I would like to change the color of each tab based on information in cell G3 on that individual tab. For example, if cell G3 on sheet 1 = 'Water Production' change the tab to green. Is there a way to do this for every tab without having to each tab individually?
This comment was minimized by the moderator on the site
I want to set the sheet tab color based on the color of cell j4 in each sheet. There are 18+ Tabs and want to update the tab colors when the workbook is opened. If I can’t update when opened I can run the macro after the teams update the sheets.
This comment was minimized by the moderator on the site
Hello, wood
To solve your problem, please apply the below code: (Note: Copy and paste the below code into the ThisWorkbook code mode)
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Call SetSheetColor
End Sub

Private Sub Workbook_Open()
Call SetSheetColor
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Call SetSheetColor
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Call SetSheetColor
End Sub

Sub SetSheetColor()
Dim xWShs As Sheets
Dim xRg As Range
Dim xFNum As Integer
Dim xSh As Worksheet
On Error Resume Next
Set xWShs = Application.ActiveWorkbook.Sheets
For xFNum = 1 To xWShs.Count
    Set xSh = xWShs.Item(xFNum)
    Set xRg = xSh.Range("J4")
    xSh.Tab.Color = xRg.Interior.Color
Next
End Sub


https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-color-sheet.png

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
I would like my tab to change color if any cell in column O or column P has a value in it. Is this possible?

Thank you!
This comment was minimized by the moderator on the site
Hello ,
I require some help
I need to change the sheet tab color only if in a certain range of cells, has today's date
Say for example,
Column L has some dates in the format (13-May-22)
One of the cell value is today's date, then the tab sheet color should change to red
Please help
Thank you in advance
This comment was minimized by the moderator on the site
Im looking to change to color of the tab based off one of 2 outcomes of a formula I have a formula of=IF((AND(AA1="Occupied",AA2="Occupied",AA3="Occupied",AA4="Occupied")),"Occupied","Vacant")
I need the tab to be red if "Occupied" and green if "Vacant". However the code above in the main post doesn't recognize the output of the If Than
This comment was minimized by the moderator on the site
Hello, Trying to have tab colour change based on value on a seperate sheet called Tracking here is what I tried but it does not seem to be working. Thanks




Private Sub Worksheet_Change(ByVal Target As Range)

'Updateby Extendoffice 20160930

If Target.Address = "Tracking!$C$2" Then

Select Case Target.Value

Case "ip"

Me.Tab.Color = vbRed

Case "w"

Me.Tab.Color = vbYellow

Case "c"

Me.Tab.Color = vbGreen

Case Else

Me.Tab.Color = vbBlue

End Select

End If

End Sub
This comment was minimized by the moderator on the site
Hello, Brad,
To make the code run correctly, you should not insert the sheet name into the code, please apple the following code:(click the sheet name you want to run this code, and then right clik the sheet name, and choose View Code, then paste the code into the module)

Private Sub Worksheet_Change(ByVal Target As Range)

'Updateby Extendoffice 20160930

If Target.Address = "$C$2" Then

Select Case Target.Value

Case "ip"

Me.Tab.Color = vbRed

Case "w"

Me.Tab.Color = vbYellow

Case "c"

Me.Tab.Color = vbGreen

Case Else

Me.Tab.Color = vbBlue

End Select

End If

End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hello,

Never done code in excel before. I need a code that do what this code do, but I need another parameter.

So what I need is:

If cell value is not 0, and/or if some other cell has numbers in it, using count, then change color to red

If cell value is 0 and those other cells are empty, using count, then change color to green
This comment was minimized by the moderator on the site
How would you link the tab to a value in a different tab. In my example I have one tab with all the information that filters out to various tabs automatically. However each tab will read green or red, depending on whether there is a bAlance outstanding on the master tab. Can this be done using this code and if so, where do I write the link to the master sheet within this code?
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