Help with vba code

PCC2019

New Member
Joined
Jun 7, 2017
Messages
7
I have a code that I have written to change the tab color of that particular worksheet if information was written in that worksheet but I have found a bug and I was hoping that someone here could look at the code and help me work this out. The code works beautifully except for one small detail... Basically if I enter information into a worksheet and tab to the next cell the code does what I intended it to do and the tab turns red indicating that this sheet has information and needs to be printed at end of day reporting. However, if I enter information into a cell and don't tab to the next cell and instead click on a different worksheet tab then the worksheet tab I just clicked on will turn red instead of the worksheet tab that has the information. I have been careful in my process as to not have the wrong sheet turn red but mistakes happen and I would like to eliminate the chance of this error in the future. Any help would be much appreciated. Thank you in advance!

below is the code I've written:


Private Sub Worksheet_Change(ByVal Target As Range)
MyVal = Range("A55").Text
With ActiveSheet.Tab
Select Case MyVal
Case "1"
.Color = vbRed
Case Else
.Color = RGB(0, 176, 240)
End Select
End With
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
MyVal = Range("A55").Text
[COLOR=#ff0000]With Target.Parent.Tab[/COLOR]
Select Case MyVal
Case 1
.Color = vbRed
Case Else
.Color = RGB(0, 176, 240)
End Select
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top