excel date time cell being covertet to numeric and cant stop it - excel

i have two sheets the first one to call a value from the second sheet, in the first sheet i have
=IFERROR(VLOOKUP(B2,'sheet'!B5:'sheet'!I2500,8,FALSE),"")
this works fine for all full text fields
but when i have a date time of
04/26/2013 11:27:00
it converts it to 41390.47708
if i manually edit the cell and put in an apostrophe it is fine but if i try and use a macro or another column to add the apostrophe it changes it to a number and then adds the apostrophe.
is there a way to get the formula to treat the cell as text

When you use a function like VLOOKUP it only retrieves the underlying value from the referenced cell, not the formatting (and display of date and time is achieved by formatting) - can't you just format the cell with the formula in the required format?
Right-click on the cell and choose Format Cells > Number > Custom and type this in the box
mm/dd/yyyy hh:mm:ss
If the formula might retrieve text or a date/time you can still format it that way because the text will be unaffected

Related

Extracting substr and concat In Excel not working as it should

So I have an excel file which has a date column in the format mm/dd/yyyy Like in this picture:
I want it in the format dd/mm/yyyy and i tried formatting the cells but they dont change. at last I chose to simply extract and concat the dates in a new column but it works for some cells while with others not.. this is the result:
As you can see sometimes it works and sometimes not. this is the formula I used (please bear in mind I am just starting out with excel and I have no clue of tricks or other methods) :
what is causing the faulty results in some of the cells ? TIA
Edit: Link for the data https://data.world/markbradbourne/rwfd-real-world-fake-data/workspace/file?filename=Call+Center.csv
If they are true date then can use-
=TEXT(A2,"dd/mm/yyyy")
If they are date format stored as text then can try-
=TEXT(DATEVALUE(A2),"dd/mm/yyyy")
If you need to extract strings then concat and convert to dates then try-
=DATE(RIGHT(A2,4),LEFT(A2,2),MID(A2,4,2))
You should use the DATE formula and then format as you need
=TEXT(DATE(RIGHT(E2,4),MID(E2,4,2),LEFT(E2,2)),"dd/MM/YYYY")
DATE formula takes Year, Month, Day as parameter - and converts that into a valid date.
TEXT then does the formatting for the output
Perhaps you should first try in using Text To Columns which in built in Excel, Under Data Tab, Grouped under Data Tools,
So just select those range, Goto Data Tab --> Click On Text To Columns --> Then select Delimited in the First Step --> Next --> Next as well in the Second Step --> and in the Third Step click on Date and change it to MDY and change the destination to adjacent cell and press Finish.
Since Dates & Times are stored as Numbers in Excel hence it will return you as numbers therefore you just need to format it as dd/mm/yyyy by pressing CTRL 1 --> Format Cells dialog opens --> under Number Tab --> Click on Custom and type by removing the General --> dd/mm/yyyy.
Using TEXTJOIN() & MID() Functions, assuming you are using either Excel 2019/2021 or MS365
• Formula used in cell B2
=TEXTJOIN("/",,MID(A2,{4,1,7},{2,2,4}))+0

Conditional formatting is not working for less than TODAY(), only for greater than

Conditional formatting does not apply to dates less than TODAY(), only greater than TODAY().
I have an IF statement with two VLOOKUPS inside. One of them outputs "Not Registered" if the cell looked is empty. The other, just copy the data that is on the other spreadsheet.
=IF(VLOOKUP($A5,Table,#MATCH(D$3,Headings,0))=0,"Not
Registered",VLOOKUP($A5,Table,#MATCH(D$3,Headings,0)))
Conditional formatting is set to:
cell values >= TODAY() are green
cell values < TODAY() are red
cell values = "Not Registered" are yellow
I suspect the conditional formatting is not reading properly the date. Every date cell is formatted as long date.
The problem comes up because A3 is empty.
Change the rules to use =Today() or populate A3 with the desired date.
Edit 1: If this is not working for you, check the data type of cells that should be red. If these are not real dates (but text), then they will never meet the condition. Make sure that all cells that look like dates actually contain dates (and not text).
If the lookup table stores the dates as text, then you can make the changes there, because the Vlookup will return the same data type.
Edit 2: Selecting a cell and changing its format will NOT convert text to a date. You can test if a date is really a date by changing its format to General. If this results in the cell showing a number, then it's a real date. But if the cell appearance does not change, the value is text and you need a different approach.
One option would be to use a helper column with a formula like =DateValue(A1). Copy the helper cells and paste them as values over the original cells, then format as date.
Or, put a zero into any cell, copy the cell, then select all cells that may or may not be dates and use Paste Special > tick "Add" > OK. That will convert dates stored as text back to their internal storage number. Then format the cells as dates.
Or, do the conversion after the Vlookup by wrapping a DateValue around the VLookup formula.
=DATEVALUE(VLOOKUP("a",A1:B1,2,0))
The "date" in B1 is really text. The Vlookup returns it as text, but the DateValue() then converts it to a date. If this one throws an error, the date text does not agree with your regional settings of what a date is expected to look like.
Reason:
Whenever the cell go past by the Less than today rule, computer will read that as zero so it will return true because zero is less than today.
Solution:
On the Conditional Formatting Rules Manager,try to enable the Stop if true for the not registered rule.

how to format time from HH:MM:SS to HHMM in excel?

I have an excel sheet in which one of the column is transaction time and its format is HH:MM:SS. But I need transaction time in HHMM format so that i can upload that excel sheet into my application. As of now i am manually formatting each row, is there any way i can apply required format to whole column at once?
If for your eyes only:
select whole column, right click somewhere in your selection, go to Format Cells, tab Number, Catergory Custom.
Type HHmm
Press OK
done.
If you need this as the actual value:
make a column containing the following formula =TEXT(<targetcell>;"HHmm")
Note that it is language-dependant whether you need a , or ; in that formula.
You have two options:
Custom format the field.
Use a function in another cell. Suppose, cell A1 contains the text 15:48:58. You use the formula in another cell (say B1) as =TEXT(HOUR(A1),"00")&TEXT(MINUTE(A1),"00"). This gives the output as 1548.
For example, type .633 in B2 cell. When we convert 0.633 to time means we convert 0.633day. We consider 24 hours as 1 day.
Follow the steps:
Select B2 cell and right click.
From shortcut menu, go to Format cells. Format cells dialog box appears.
In the dialog box. click custom under Category list. Find hh:mm:ss from right list.
Now edit it as hhmmss in the right side just under 'Type:'.
You may read this tutorial from msofficeworld: Format Time in Excel

Excel, change format of a date, then make ALL cells in column look the new way

I have a file where the date column is in a format I cannot make calculations, so I changed the column to another format where I can subtract dates. As usually happens with excel though, only when I double click an entry it changes to the new format.
Does anyone know how I can force all the cells in column to change to the new format, in order for my script to be able to subtract dates for the whole file?
Here is a really easy work-around:
Insert a blank column.
Change the format of the blank column to the date format that you want.
Copy the column with the dates that won't format.
Right-click on the first cell of the blank, formatted column, select Paste Special, select Paste:Values and Operation:Add. (Because the destination cells are blank, the dates will be unchanged.) Click OK.
The dates will now appear as dates.
Try this in your vbScript
objExcel.Cells(Row, Column).NumberFormat = "#0.00"
If you just want to do this via VBA, you can use something like this:
Range("C1:C100").NumberFormat = Range("B2").NumberFormat
The example above just changes the format for cells C1-C100 to whatever the format is in B2.
Update:
I noticed you said that the format is working fine, but dispalys as #######. This typically happens when the column is not wide enough to show the whole value, so resizing it manually or using something like the belwo should fix your issue:
Columns("C:C").EntireColumn.AutoFit
You may also want to try =Datevalue() in an adjacent column. My experience in these types of situation is that Excel doesn't understand that your entries are dates. They are text, and will not change to date simply on a format change. Alternatively you can try text to columns to do the conversion.

In excel: How to determine if 01/01/1900 then print out empty string, otherwise show the date

I'm trying to show all dates except for 01/01/1900. In excel, how do I first check for 01/01/1900 and then replace only that date with empty string or "", but leave any other dates alone? I also need to keep the format set to small date format of mm/dd/yyyy.
I tried to use replace, if, date, datevalue commands without successs.
Another answer which does not affect your data, but only the presentation layer is to set up a custom formatting. Choose the cells you want, and press CTRL+1 or choose Format Cells from the Format menu. Then under number format, Date should be selected. Click on Custom at the bottom of the list, then add two semicolons after the formatting string picture that is there.
A custom formatting string can have three (sometimes four) pictures seperated by semicolons. The first is for positive numbers, the second for negative, and the third for zero.
My formatting string looks like this: 'm/d/yyyy;;'. All zero dates (1/0/1900) will be blank. No extra column needed.
Create a new column next to your column with dates, and use this formula for every cell (A1 here refers to the source cell):
=IF(A1<>DATE(1900,1,1),A1,"")
Then format your new column as a date.

Resources