Need some help with a spreadsheet that i have created as a timesheet rota. Basically i would like to highlight cells in the below calendar where the date is less than today and the cell is blank to identify when people have not entered the shift they have worked.
For example on the calendar i would like the top three rows where nothing has been submitted to highlight red
Is this possible?
Thanks in advance for the help!
Put this code in the worksheet module and adjust the range to suit what you need. Change this Range("A1:C10") to suit the ranges that you want affected.
The code will determin if the cell is empty or has a date before today and change the color to red.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:C10")) Is Nothing Then
If Target Is Nothing Then
Target.Interior.ColorIndex = 3
ElseIf Target <= Date Then
Target.Interior.ColorIndex = 3
End If
End If
End Sub
You could use conditonal formating. You have to do the following for every month.
Select a cell (for example E10). Goto [Condional Formating (on the Home tab) >> Highlight Cells Rules >> more Rules >> Use a formula to....].
Type
=AND(E$5<TODAY(),E10="")
in the textbox and choose a format (like highlighting red).
Then apply this formatting to all the cells in that particular month (Conditional Formatting >> Manage Rules)
Repeat this proces for the other months.
Related
I have created a VBA code which displays with a blue colour the entire column where the today's date is located. The problem I have now is that my code does not uncolour the past dates. That means the colour of the past dates and the today's date is the same. I want only one column to be coloured which is the column of the today's date. I do not want for the past dates to have the same colour with the today's date. Current code below:
Any ideas?
Private Sub Workbook_Open()
Dim CellToShow As Range
Worksheets("Sheet2").Select
x = Day(Date)
Set CellToShow = Worksheets("Sheet2").Rows(3).Find(What:=x, LookIn:=xlValues) 'my dates are located across row 3
CellToShow.EntireColumn.Interior.Color = RGB(151, 228, 255) 'background colour in the selected cell
If CellToShow Is Nothing Then
MsgBox "No Cell for day " & x & " found.", vbCritical
Else
With CellToShow
.Select
.Show 'Scroll the window to show the cell
End With
End If
End Sub
EDIT:
Here is the image of the problem.As you can see, Excel does put a colour in the column that contain the today's date. But also already colours the yesterday's date. I do not want yesterday's date been coloured.
https://i.stack.imgur.com/oBf9P.png
Use Conditional formatting - set 'Applies To' to be the whole worksheet $1:$1048576, and the formula to be =A$3=DAY(TODAY()). All the vba has to do is the message box if no relevant date is found, and scroll to the relevant column.
EDIT:
The reason this will work is because conditional formatting formulas are written for the first (top-left) cell in the range to be formatted (so for the whole sheet, this formula is written how it would apply to cell A1. The formula is then applied to other cells in the range in the same relative way - hence the use of A$3, the $ fixes it to always refer to row 3, while the A is left to change dynamically for each cell to be coloured. In this way the formula applies to whole columns, because the row reference is fixed.
I currently have the following in excel for other users.
The Number column does not change. Users will input values in Multiplier 1 and Multiplier 2 columns and they will get a value in Outcome column.
Is there an automatically way where the user can also input a value in Outcome column and the Multiplier 1 column will change?
Currently Number and Outcome column are protected, will I need to unprotect the Outcome column?
I recommend you use some VBA code using the Sub Worksheet_Change(ByVal Target as range) in the worksheet.
If the user enters a value in D2 it will put the formula "=D2/(A2*C2)" in B2
If the user enters a value in B2 it will put the formula "=A2*B2*C2" in D2
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count > 1 Then Exit Sub
On Error GoTo LastLine
If Not Intersect(Target, Range("D2")) Is Nothing Then
Range("B2").Formula = "=D2/(A2*C2)"
ElseIf Not Intersect(Target, Range("B2")) Is Nothing Then
Range("D2").Formula = "=A2*B2*C2"
End If
LastLine:
Application.EnableEvents = True
End Sub
This can be done. Begin by noticing that your formula is so simple that you
Can easily solve for multiplier1 as a function of:
outcome divided by (number times multiplier2)
Next get tricky by adding a 1 pixel wide column that will contain your formula
for outcome to the right of (now an input not a formula) the original
outcome column.
Similarly add a 1 pixel wide col to the right of multiplier1 that contains
your new formula for multiplier1. Adjust data validation on original input
cells for multiplier1 and outcome to allow only one of the two to be
entered at a time (use isblank function appropriately in an excel custom data
validation rule for each cell).
Finally right align the two 1 pixel wide cells so that their calculated values
appear within the corresponding enterable cells when they are blank.
Yes it's tricky but it works.
Sorry this is just an outline but I have used this in an application and it
works great. No vba, so undo redo don't break. Try it you'll like it.
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.
I have some code in a worksheet to highlight the row of a selected cell. However, this sheet has conditional formatting which colours some of the rows. The highlighting macro does not work on the rows where the formatting condition is being met (in the sense that the colour of the highlight is not overriding the colour of the conditional formatting).
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlColorIndexNone
ActiveCell.EntireRow.Interior.ColorIndex = 19 'Highlight row
End Sub
Does anyone know a way around this without removing the conditional formatting?
Eg. can I temporarily disable it for a selected row and re-enable it when the row is unselected?
The formatting is one rule applied to all cells. I figure in theory I could create an independent rule for every row (~500 of them) and then turn that off completely and later reapply it but that seems a little overboard.
There is no need to use ActiveCell in your Worksheet_SelectionChange event macro. That is what Target is/does.
Modify your Worksheet_SelectionChange to be closer to the following.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Name = "mySelection"
Cells.Interior.Pattern = xlNone
Target.EntireRow.Interior.ColorIndex = 19
End Sub
Now you will be constantly redefining a named range for each new selection of cells.
You didn't disclose what the CF rule actually was so I'm going to assume that is highlights cell that are not blank. Modify the existing CF rule to be of the Use a formula to determine which cells to format variety and adjust the following to suit your own CF rule then put it in the Format values where this formula is true: text box.
=AND(A1<>"", ROW(A1)<>ROW(mySelection))
By adding a boolean criteria within an AND function and constantly redefining the mySelection range to the current selection you can override the CF rule's formatting.
I'm working on a spreadsheet to record vehicle mileage. I'd like to manually enter starting mileage in F6 and ending Mileage in G6. I'd like the value of G6 to then automatically be copied to F7 and I'd enter the ending mileage in G7- and so on. The problem I have is dealing with weekends and holidays when 2 or 3 blank cells may occur. I've tried using something like =if(D9=""," ", G6), but this doesn't work.
I've also tried this function in VBA: =IF(D9=""," ",LastNonBlankCell(G8:G39)) [D9 is a datefield] and only ended up with 0's.
Function LastNonBlankCell(Range As Excel.Range) As Variant
Application.Volatile
LastNonBlankCell = Range.End(xlDown).Value
End Function
Do you really need the blank rows for weekends or holidays? If not, set D8 to the formula =workday.intl(D7,1) then copy it down as far as needed. If you need to allow for holidays, see the Excel documentation for WORKDAY.INTL. The list of dates will now contain only workdays, so the ending mileage for one row can be copied down to the next with no special handling.
This makes weekends and holidays harder to see at a glance. That can be addressed using conditional formatting. Setup formatting for the range D8:D<whatever>, use the formula =D8>(D7+1), and set the formatting to whatever stands out for you.
The following VBA macro will achieve your end goal in a slightly different way than what you asked about.
After you have installed the macro, when you double-click on a cell in column G, the macro will copy the last entered ending mileage to the cell to the left in column F.
For example, if the last ending mileage entry was in cell G6 and you double-click in cell G9, that entry will be copied to cell F9. You can then enter the new ending mileage in cell G9.
Private Sub WorkSheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Application.Intersect(Target, Range("G:G")) Is Nothing Then
Selection.Offset(0, -1).Value = Selection.End(xlUp).Value
Else
Exit Sub
End If
End Sub
To install the macro, right-click on the worksheet's name tab, select "View Code", and paste in the macro code. It won't work if you put the code into a regular module.