简体   繁体   中英

Using weeknum on date and time text results with #VALUE

So my friend has this template he got from his boss, it's got a bunch of dates and times and other data. He told me he created a new workbook and copied everything from the template to this new workbook and then he modified the dates. The date and time listing he copied from another file.

So this is where the problem occurs, when he's done copying, one entire column resulted with #VALUE! instead of expected result w/c would be in yy/ww format. The formula is written below:

=MID(N2,9,2)&"/"&IF(LEN(WEEKNUM(N2,1))=1,"0"&(WEEKNUM(N2,1)),(WEEKNUM(N2,1)))

Inside N2 is 26/08/2014 1:27 PM . So I googled a bit and found out that WEEKNUM doesn't work for text-style date and time. Should only work with serial numbers, if I understand it correct. I checked the N column (which was all copied from another file) and they were all in text. But when I checked the template, the dates were also all in text style. So how the formula worked with the template but not with the new workbook? (I'm assuming that every text in every cell is aligned to the left, dates in both new workbook and the template are both aligned to the left.)

I told my friend that the N column should be in date format so I suggested him this formula:

=(DATE(2014,8,26) + TIME(13,27,0))

And finally it worked. But his and my concern would be that we can no longer just copy and paste the dates but manually input every date within the formula. But there's just too many dates and it would take a long time to finish.
Any way around this?

UPDATE: I just noticed something. The format of the dates copied is dd/mm/yyy h:mm AM/PM. When I checked on the column where all the #VALUE! s are spawning, there are exceptions. I actually found 3-4 cells that are normal. The date is: 02/10/2014 3:49 PM and the result with using the formula is 15/49 . I'm wondering, could it have been with how the dates are typed in? Or rather copied in? Like, should the date format be in mm/dd/yyyy instead of dd/mm/yyyy?

Used evaluate formula and it said that N2 contains a constant.

The WEEKNUM function works with dates as text while it can implicitly convert the text to date. Example:

Input '31/03/2015 in A1 and =WEEKNUM(A1) in B1. Input '03/31/2015 in A2 and =WEEKNUM(A2) in B2. Note the leading ' before the dates. They will convert the inputs to text. One of them will work, one will not. This will indicate which is your default date format dd/mm/yyyy or mm/dd/yyyy .

You say both Excel are English but there is a difference in default date format between GB English and US English unfortunately.

So if the dates are text in dd/mm/yyyy format and your default date format is mm/dd/yyyy , you can't simply copy them into your Excel and work with them. You have to change them ever to mm/dd/yyyy first. Ever, because even the values which seems to work are mostly wrong. WEEKNUM with the text 09/11/2015 will work even with default date format mm/dd/yyyy . But it will implicitly convert the text to September 11. 2015 while with dd/mm/yyyy 09. November 2015 was meant.

Best solution ist not to use dates in text format. If your friend's boss had used date values instead of text then copy&paste would work. But because he had not, you have to convert the formats in a helper column now. Try

=MID(N2,4,2)&"/"&LEFT(N2,2)&"/"&MID(N2,7,999)

copied down in a helper column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM