Automate Tab Colour in Excel - excel

Good afternoon,
I have cells the first has a date and the second has a date, and the third checks the first two. If the first cell has a value it returns "OPEN", if the second cell has a value it instead returns "WAITING",
eg. Cell F4 "=IF(D4=0,"",IF(AND(D4>0,E4=0),"OPEN","WAITING"))"
and then I put a date in that cell replacing the formula.
Then another cell checks the whole column and if it contains "OPEN" or "WAITING" it's value is "OPEN", if not it's value is "CLOSED",
eg. Cell M2 "=IF(SUM(COUNTIF(F2:F1000,{"OPEN","WAITING"})),"OPEN","CLOSED")"
Then I have VBA on the tab colour, which changes to either green if that cell is "CLOSED" or red if it's "OPEN".
eg.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$M$2" Then
Select Case Target.Value
Case "OPEN"
Me.Tab.Color = vbRed
Case "CLOSED"
Me.Tab.Color = vbGreen
Case Else
Me.Tab.Color = vbOrange
End Select
End If
End Sub
This all works except for the tab colour. I have to open the M2 cell (which has calculated correctly) and press enter to activate the tab colour change.
The cells that are checking previous cells are not always column F, some are different. The final value is always M2 in every sheet.
The reason I tried to do this was so I wouldn't need to change the tab colour manually. Is there a better way to do this? I'm currently achieving no automation, if anything it's slightly more work.

Related

Excel Highlight Second Entry within a Range of Cells

I am trying to highlight the cell of a second entry (and beyond) within a range of cells. I am tyring to implement this feature in my attendence tracking.
For example, in the image below, I have "Peter", "John" and "Tom". If there are only one person who is absent, I do not need to highlight anything, as shown below.
However, if either "Tom" or "John" is the second person to be entered as "Not in" (absent), I want to highlight the cells, as shown below.
Finally, if the last person left is also absent, I would like to highlight it as well, like below image
The values in Column C is not restricted to these phrases ("Absent","Away","Not in").
From another point of view, I want to highlight the second and the later entries within a range of cells. Is there a way to implement such feature without using VBA or macro? Can it be donne using conditional formating?
Please advise. Thank you so much!
You can use the Worksheet_Change event to add a timestamp to a helper column. In my case, I added it to column D:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myrange As Range
Set myrange = Range("C3:C9")
If Not Application.Intersect(myrange, Range(Target.Address)) Is Nothing And Target.Count = 1 Then
If Target.Value = "" Then
Target.Offset(0, 1).Value = ""
Else
Target.Offset(0, 1).Value = Now()
End If
End If
End Sub
Then use conditional formatting on column C using something like this:
=$D3>=SMALL($D$3:$D$9,2)
This will highlight any rows where the the timestamp is greater than the second smallest timestamp (ignoring blanks).
Here's an example of it in action. For illustration purposes, I put the order I typed things in column C rather than "Absent", "Not Here", etc.

Auto-populate cell, based on another cell's value, without formulae

I've seen a couple of spreadsheets over the years that had a blank, unpopulated, non-formula cell, that would populate when another cell was populated correctly. I am wondering if there is a way to do this without using add-ons, or VBA.
Scenario:
User is asked to enter a value in cell A1.
If the value is X, cell B1 populates with a value.
If the value is Y, cell B1 remains blank.
I know that this can be done with a formula such as =IF(A1="","",IF(A1=1234,"Hello 1234","")).
However, I am wondering if it is possible to do this without a formula in cell B1, but still have cell B1 populated?
From your description, it sounds like this might be what you witnessed. Macros can be set to trigger automatically given a certain event & criteria met. In this instance, the macro will fire when you make a Worksheet_Change in cell A1.
Note that the change to A1 must be manual to fire macro - a change due to formula will not suffice to trigger macro
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
If Target = "X" Then
Range("B1") = "X Result"
ElseIf Target = "Y" Then
Range("B1") = "Y Result"
End If
End If
End Sub

Excel macro for cell fill in with one click based on dropdown list

I want to fill a range of cells let's say A1:A5 with the value that is in a drop down list let's say in B1, by clicking once with the mouse in cells A1:A5. The way i want it to work is to first select the value that i want from the dropdown list and then click in in any of the cells from range A1:A5, and only the cell selected changes the value to the value from the dropdown list. And also when i change the value from the dropdown list the cells that were previously filled by clicking them do not change automatically to the new value from drop down. Once clicked they remain to that value until clicked to another selected value.
Add data validation to B1, under "Allow:" you pick "List", under "Source:" your values like: Value1,Value2,Value3... .. or of course a range..
Paste the following in sheet code(eg Sheet1(sheet1))
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
Selection.Value = Range("B1").Value
Range("B1").Value = ""
End If
End Sub

date in a cell to change when any cell in that row is modified

I'm relatively new to excel and need some advice. I'm using excel 2016. I have read through other posts and can't find anything that really matches. Does anyone know how to get a cell in a row to change to todays date only when any other cell in that row is changed? And secondly if that date in that cell is more than week old and the value of another cell in the same row is "open" then change the fill color? thanks for any insight you can provide.
You'll need some VBA for this. Get into Visual Basic Editor (VBE) with Alt+F11. In your VBAProject (your workbook in the Project window) double click the sheet that contains the cell in which you are wanting to detect a change. Then add the following::
Private Sub Worksheet_Change(ByVal Target As Range)
'Detect if cell A1 has had a change
If Not Intersect(Target, Range("A1")) Is Nothing Then
'Change cell B2 to todays date
Range("B2").Value = Now()
'Detect if value in cell C2 is changed to "Open"
ElseIf Not Intersect(Target, Range("C2")) Is Nothing Then
'Is the date in B2 older than a week from now?
If DateAdd("d", -7, Now()) > Range("B2").Value Then
'Change the cell color of B2
Range("B2").Interior.Color = RGB(0, 255, 255) 'Cyan... it's so beautiful
End If
End If
End Sub
That subroutine is a special subroutine that runs when any cell changes value in the worksheet in which the subroutine is placed. We detect if a change was made to a specific cell with that awful If Not Intersect(... line. Then it's pretty straight VBA to change values and colors of cells and do some date arithmetic and tests and whatnot.

Excel: Dropdown style selector

Currently I am using Data Validation to select from a list of options a cell can be. Is it possible to do the same thing but with styles? I.e. from the dropdown I can select a subset of styles I would like to apply to the cell?
Add some code to change the format of some cells, based on the value change of certain cell.
Let's say that you want to change the color of cell D2 based on the value of cell B2 (both in Sheet1). Open your VBA editor, double click on "Sheet1" of your book in your Project browser and select the Worksheet object and the Change procedure, and do something like this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then ' This is the address of the cell being changed
Select Case Target.Value
Case 1 ' The changed cell value is 1
ThisWorkbook.ActiveSheet.Range("d2").Interior.Color = RGB(125, 125, 125)
Case 2 ' The changed cell value is 2
ThisWorkbook.ActiveSheet.Range("d2").Interior.Color = RGB(125, 125, 255)
Case 3 ' The changed cell value is 3
ThisWorkbook.ActiveSheet.Range("d2").Interior.Color = RGB(125, 0, 255)
End Select
End If
End Sub
You can google around to find ways to change other format properties of the cell.

Resources