We help IT Professionals succeed at work.

strange bug (?) in Excel: I need to F2 + press ENTER to make the results of the formulas work

lucavilla
lucavilla asked
on
With the attached file, why do you need to edit (double click) the cell B2 and press ENTER to make the formula in cell F2 show the correct result (18:14:32)?

How can I fix the results in F all at once without editing and pressing ENTER on every single cell in B?


(tested on Excel 2010)
debug.xlsx
Comment
Watch Question

Director, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014
Commented:
Because column B is currently text, not a time. By going in cell B2 and pressing ENTER, it forces it to re-evaluate the cell and changes it to time.
 
To change them all at once, highlight column B, press Ctrl+H, and enter : in both the FIND and REPLACE. It will then replace a colon with a colon, which forces Excel to re-evaluate all those cells.
NorieAnalyst Assistant
Commented:
B2 is a time stored as text, doing what you describe will convert it to a 'real' time.

If you want to convert all the values in that column copy a blank cell, select the values in column B, goto Paste>Paste Special and select Add from the Operation section.

That will fix the values but you'll lose the formatting but you can easily reapply that from column F with the format painter.
Commented:
I don't think changing format will  fix the problem

try this code
Public Sub fixtime()
Dim ii As Integer
For ii = 1 To ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Cells(ii, 2).Value = ActiveSheet.Cells(ii, 2).Value
Next
End Sub

Open in new window

Rob HensonFinance Analyst
Commented:
In a spare column type formula

=TIMEVALUE(B2)

Copy down as required then copy and paste values into column B, reformat as time.

The same applies to the values in column D.

Thanks
Rob H
Phillip BurtonDirector, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014
Commented:
Ignore my earlier suggestion (even though it was right).
 
You also have to edit column D, so it’s easier to change the formula in F2 to:
 
=(NETWORKDAYS(A2,C2,{42005;42010})-1)*0.354166666666667+MIN(MAX(VALUE(D2),0.354166666666667),0.708333333333333)-MIN(MAX(VALUE(B2),0.354166666666667),0.708333333333333)
Rob HensonFinance Analyst
Commented:
Or in the formula in F, wrap the references to B & D in TIMEVALUE function:

=(NETWORKDAYS(A2,C2,{42005;42010})-1)*0.354166666666667+(IF(TIMEVALUE(D2)<0.354166666666667,0.354166666666667,IF(TIMEVALUE(D2)>0.708333333333333,0.708333333333333,TIMEVALUE(D2)))-IF(TIMEVALUE(B2)<0.354166666666667,0.354166666666667,IF(TIMEVALUE(B2)>0.708333333333333,0.708333333333333,TIMEVALUE(B2))))

Thanks
Rob
Rob HensonFinance Analyst
Commented:
Which looking at it again, is pretty much what Philip has done but has just used VALUE (which gives serial value of text time) and has used MIN/MAX functions to shorten the IF statements.

Thanks
Rob H
NorieAnalyst Assistant
Commented:
What I suggested can be extended to the other column and by using that method, or similar, you end up with 'real' time values and don't need to change any formulas.
Most Valuable Expert 2013
Commented:
I'm not going to answer your question (!) but if all reference values are true dates or times I'd suggest using this shorter formula using more recognisable time values

=(NETWORKDAYS(A2,C2,{42005;42010})-1)*("17:00"-"8:30")+MEDIAN(D2,"8:30","17:00")-MEDIAN(B2,"8:30","17:00")

Personally I would also replaced the holiday range with a cell reference which contains recognisable holiday dates

regards, barry