[英]Change sheet tab color based on cell value?
I am trying to create a macros that changes the tab color based on the name appearing in a specific cell on a sheet.我正在尝试创建一个宏,该宏根据出现在工作表上特定单元格中的名称更改选项卡颜色。 The names appear in cell
b11
.名称出现在单元格
b11
中。 I have seven different names that may pop up depending which means that the specific sheet is for them to use.我有七个不同的名称可能会弹出,这取决于具体的工作表是供他们使用的。 I am trying to tie a color to their name and have the color reflect on the tab.
我正在尝试将颜色与他们的名字联系起来,并让颜色反映在标签上。
This is the formula that I tried and used but honestly, I'm just shooting in the dark here.这是我尝试和使用的公式,但老实说,我只是在这里在黑暗中拍摄。 I have no idea what I am doing.
我不知道我在做什么。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$11" Then
Case "Arica"
Me.Tab.Color = vbYellow
Case "Amy"
Me.Tab.Color = vbGreen
Case "Nadia"
Me.Tab.Color = vbBlue
Case "Roelisa"
Me.Tab.Color = vbOrange
Case "Wezi"
Me.Tab.Color = vbPurple
Case "Mabel"
Me.Tab.Color = vbPink
Case "Patrice"
Me.Tab.Color = vbLightBlue
End Select
End If
End Sub
Is there anyone who can help me write a formula that executes what I desire it to do please?有没有人可以帮我写一个公式来执行我希望它做的事情? Thanks!
谢谢!
Select Case Target
) Select Case Target
)End Sub
) End Sub
) A quick look in the documentation often helps with syntax.快速浏览文档通常有助于语法。 Just saying.
只是说。
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/select-case-statement https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/select-case-statement
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$11" Then
Select Case Target
Case "Arica"
Me.Tab.Color = vbYellow
Case "Amy"
Me.Tab.Color = vbGreen
Case "Nadia"
Me.Tab.Color = vbBlue
Case "Roelisa"
Me.Tab.Color = vbOrange
Case "Wezi"
Me.Tab.Color = vbPurple
Case "Mabel"
Me.Tab.Color = vbPink
Case "Patrice"
Me.Tab.Color = vbLightBlue
End Select
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.