Excel - Conditional Formatting - Updates Based on Current Date - excel

How would I go about applying conditional formatting to a range of cells (Excel 2007) based on the current date?
I have a six-week plan (each column represents a day in the week (Monday to Friday, excluduing weekends)) and I would like to shade each column in green as the day passes without any user interaction, so that when I look at it, it will accurately have 'marked off' each day.
This is what I hope to achieve: I view the plan on Monday 1st January. I then don't access it until Thursday 4th January; once the plan is opened, I will see that the columns M-W have been shaded in green, whereas the rest of the plan for the remainder of the six weeks remains unshaded and this should continue for the remainder of the duration of the six-week plan.
Is this possible?
I would imagine that VBA would be used to check the system time and then apply the formatting according to what day it is.
Many thanks.
UPDATE
This is how my planner looks:

Sure, it's possible. The following should put you on the right track.
First, you can record the last time the workbook was accessed by storing the current date/time in a cell at the time when the workbook closes. This can be done using the Workbook_BeforeClose event, which has to be put in the workbook module. Open the VBA editor (Alt-F11), then open the ThisWorkbook module and paste this code in it.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheet1.Range("B2").Value = Now()
End Sub
Every time the workbook is closed, the date/time at closing time will be noted in cell B2 (change this as you see fit).
In cell B3, use the =NOW() Excel formula to show the current date time. Cells B2 and B3 now define the interval within which your columns should be highlighted.
Then how to format the columns... Say your columns have date headers as in the image above. Select your "calendar" range (C5:I12 in the example above) and click Conditional Formatting > New Rule... > Use a formula. The formula should be =AND(C$5>$B$2,C$5<$B$3) meaning that only the columns whose date in the header is after the workbook was closed last time, but before now (adjust as you see fit), will be formatted. Click Format... to select e.g. a green fill, or whatever. Then OK.
Of course you could refine this in many ways (e.g. rounding to the previous or next day at midnight) but at least you should be on the right track now.

Use this conditional formatting formula:
=IF(DAYS360(DATE(B$2;B$3;B$4);TODAY())>1;1;0)
what is does is
if(the difference between this colums date and today is more then 1 day, be true, otherwise false)
use it in a sheet like

Related

Date in Spreadsheet shows as number when cell format is short date

One spreadsheet in the workbook has a column of dates that appear as left justified numbers, even though the format on the column is Short Date. Cannot set the column to number format, change alignment or force any other format. When a cell is selected it shows as a date in the cell and in the formula bar, but when focus is changed, it reverts to number. How to fix this?
The spread sheet was copied from another workbook, and was apparently protected in that workbook. Thus not able to format or change anything. Ended up selecting all cells in the worksheet and pasting into a new worksheet. Able to apply changes then.

Is it possible to have excel highlight cells that don't conform to my desired format (ex. date as 6.2.2021 vs the desired 6/2/2021)?

I use a spreadsheet to prioritize workflow for my team. Certain cells highlight depending on how close we are to cycle times. There is a start date, a tentative finish date, and a discharge date.
A blank discharge date cell turns red if:
start date is not blank; tentative is not blank; and today's date is within five days of the tentative date.
Some of my team member have the habit of writing their dates with periods (mm.dd.yyyy). Excel of course does not recognize this as a date. BUT it does know that the 'tentative date' cell is not blank. As a result, even if today's date is equal to the tentative date, the 'discharge date' cell does not turn red. This is taking away from the utility of this sheet, as it is intended to be info at a glance, where a glaring red cell lets one know, "Oh shoot! I need to focus on that task as a priority."
I'd like for the start date and tentative date cells to go red if the date is not the desired format (mm/dd/yyyy).
Formula and condition in S1:
S1 fills red if
=AND($P1-TODAY()<=5,COUNTA($S1)=0,$M1<>0,$P1<>0)
In the same way that you can conditionally format the output as red with your supplied formula above, you can conditionally format the inputs (start date and tentative date) if they do not match your criteria.
One idea is to use something like =SEARCH(".", A1)>0 as the criteria for the format (if the incorrect input always comes in some variation of dd.mm.yyyy, and assuming the start of your range is in cell A1).
Here are the steps to do so if you did not create the original rule:
Highlight the ranges of the start and tentative dates
Go Home->Conditional Formatting->New Rule->"Use formula to determine which cells to format"
Enter the formula above (where you are sure to remove absolute references)
Go Format->Fill->Choose Red and hit okay

Display a "YTD" automatically for the current month with a worksheet level VBA code

can I have some ideas on how to construct this event level VBA on a worksheet level?
If current month matches the month on the cell 4 rows below ("BC5") then put "YTD" with black background in this cell ("BC1") and the previous cells in the row for the previous months.
For example, we are in June already so "YTD" should be already visible in the top row.
See image below.
Thank you.
Assuming the month headers in what looks like row 3 or 4 are real dates, you can use a formula like this in cell AX1 and copy to the right
=IF(TODAY()>AX4,"YTD","")
Then add conditional formatting to highlight cells that are equal to "YTD" and change the format to your liking.
Since there is also a LYTD (Last Year To Date), I have used the following solution:
=IF(MONTH(TODAY()) >= MONTH(AQ5), "LYTD", "")
Thank you Teylyn for the original solution.

excel date formatting not working

I have an excel sheet created by a 3rd party program.
One of the columns has dates in this format: "Jan 19, 2015 03:00:00 PM"
I would like these dates to appear in the following format: "19/01/2015"
I have selected the cell or cells, right clicked and selected "Format Cells...", chose "Date" in the category, then chose "14/03/2001" in the type, to no avail, the dates won't change.
I also tried "Custom" from the category and "dd/mm/yyyy" from the type, again, no changes at all.
The file is not protected, the sheet is editable.
Could someone explain what I could be doing wrong?
Regards
Crouz
The following worked for me:
Select the date column.
Go to the Data-tab and choose "Text to Columns".
On the first screen, leave radio button on "delimited" and click Next.
Unselect any delimiter boxes (everything blank) and click Next.
Under column data format choose Date
Click Finish.
Now you got date values
Given your regional settings (UK), and the inability of formatting to change the date, your date-time string is text. The following formula will convert the date part to a "real" date, and you can then apply the formatting you wish:
=DATE(MID(A1,FIND(",",A1)+1,5),MATCH(LEFT(A1,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0),MID(SUBSTITUTE(A1,","," "),5,5))
Might be able to simplify a bit with more information as to the input format, but the above should work fine. Also, if you need to retain the Time portion, merely append:
+RIGHT(A1,11)
to the above formula.
I had a similar problem. My Excel sheet had 102,300 rows and one column with date was messy. No amount of tricks were working. spent a whole day entering crazy formulas online to no success. See the snips
How the column looked ("Short Date" format on Excel)
The red circled cell contents (problematic ones) do not change at all regardless of what tricks you do. Including deleting them manually and entering the figures in "DD-MM-YYYY" format, or copying and pasting format from the blue ones. Basically, nothing worked...STUBBORNNESS!!
How the column looked ("Long date" format on Excel)
As can be seen, the cell contents doesn't change no matter what.
How I solved it
The only way to solve this is to:
upload the Excel sheet to Google Drive. On Google Drive do this:
click to open the file with Google spreadsheet
Once it has opened as a Google spreadsheet, select the entire column with dates.
select the format type to Date (you can choose any format of date you want).
Download the Google spreadsheet as .xlsx. All the contents of the column are now dates
DATEVALUE function will help if date is stored as a text as in
=DATEVALUE("Jan 19, 2015 03:00:00 PM")
My solution to a similar problem with Date formatting was solved by:
Copying the problem sheet then pasting it into Sheet
n.
Deleting the problem sheet.
Renaming Sheet n to the name of the problem sheet.
QED.
The problem sheet contained Date data that I wanted to read as 07/21/2017 that would not display anything other than 42937. The first thing I did was to close Excel and re-launch it. More tries followed. I gave up on my own solutions. I tried a few online suggestions. I then made one more attempt and - Walla - the above three steps fixed the problem. As to why the problem existed? It obviously had something to do with "the" sheet. Go figure!
For me to believe is insufficient for you to know - rodalsa.
With your data in A1, in B1 enter:
=DATEVALUE(MID(A1,1,12))
and format B1 as dd/mm/yyyy For example:
If the cell appears to have a date/time, but it does not respond to format changes, it is probably a Text value rather than a genuine date/time.
While you didn't tag VBA as a possible solution, you may be able to use what some feel is a VBA shortcoming to your advantage; that being VBA heavily defaulted to North American regional settings unless explicitly told to use another.
Tap Alt+F11 and when the VBE opens, immediately use the pull down menus to Insert ► Module (Alt+I,M). Paste the following into the pane titles something like Book1 - Module1 (Code).
Sub mdy_2_dmy_by_Sel()
Dim rDT As Range
With Selection
.Replace what:=Chr(160), replacement:=Chr(32), lookat:=xlPart
.TextToColumns Destination:=.Cells(1, 1), DataType:=xlFixedWidth, FieldInfo:=Array(0, 1)
For Each rDT In .Cells
rDT = CDate(rDT.Value2)
Next rDT
.NumberFormat = "dd/mm/yyyy"
End With
End Sub
Tap Alt+Q to return to your worksheet. Select all of the dates (just the dates, not the whole column) and tap Alt+F8 to Run the macro.
Note that both date and time are preserved. Change the cell number format if you wish to see the underlying times as well as the dates.
Struggled with this issue for 20 mins today. My issue was the same as MARIO's in this thread, but my solution is easier. If you look at his answer above, the blue circled dates are "month/day/year", and the red dates are "day/month/year". Changing the red date format to match the blue date format, then selecting all of them, right click, Format Cells, Category "Date", select the Type desired. The Red dates can be changed manually, or use some other excel magic to swap the day and month.
Another way to address a few cells in one column that won't convert is to copy them off to Notepad, then CLEAR ALL (formatting and contents) those cells and paste the cell contents in Notepad back into the same cells.
Then you can set them as Date, or Text or whatever.
Clear Formatting did not work for me. Excel 365, probably version 2019.
Select the cells you want to format.
Press CTRL+1.
In the Format Cells box, click the Number tab.
In the Category list, click Date.
Under Type, pick a date format.
The only way to solve this is to:
upload the Excel sheet to Google Drive. On Google Drive do this:
click to open the file with Google spreadsheet
Once it has opened as a Google spreadsheet, select the entire column with dates.
select the format type to Date (you can choose any format of date you want).
Download the Google spreadsheet as .xlsx. All the contents of the column are now dates
Select the column ->
Go to "Data" Tab -> Select "Text to Column" ->
Select Delimited -> check Tab ( uncheck other boxes) -> Select Date -> Change format to MMDDYYY -> Finish.
Similar way as ron rosefield but a little bit simplified.
=DATE(RIGHT(A1,4),MATCH(MID(A1,4,2),{"01";"02";"03";"04";"05";"06";"07";"08";"09";"10";"11";"12"},0),LEFT(A1,2))

Excel dynamic conditional formatting based on cell version 2

A few months back I posted the following question Conditional formatting rows based on cell dynamic.
At the time the formula provided was fantastic and still is however I'm redeveloping the spreadsheet and need something similar but I just can't figure out a solution.
I currently have a list of times in column A in increments of 1 hour from 9am to 9pm. In column B I would type 2 next to 9am it would somehow highlight 9am and 10am, now under that say you type 7 next to 11am it would highlight 11am, 12pm 1pm 2pm 3pm 4pm 5pm.
Hope that makes sense
Many Thanks
This would seem to require the Use a formula to which cells to format option when creating a new CF rule.
                 
Select A2:B14 with A2 as the Active Cell and choose Home ► Styles ► Conditional Formatting ► New Rule. Select the Use a formula to which cells to format option and supplt the following for Format values where this formula is true:
=AND($A2>=INDEX($A$2:$A$14,MATCH(1E+99,$B$2:$B2)),$A2<(TIME(VLOOKUP(1E+99,$B$2:$B2,1),0,0)+INDEX($A$2:$A$14,MATCH(1E+99,$B$2:$B2))))
Click Format and select some formatting. I chose an orange Fill. Click OK to save the formatting choice(s) and then OK again to create the new rule. You should be left with something similar to the above sample image.

Resources