Custom format cell to consider dash as zero in excel - excel

I import data from web external query in excel in which zero value represented as dash, to further calculation on this I need to consider this dash as zero
for that I have macro to convert dash to zero but, data gets refreshed every 5 min. so I need to run that replacement macro every 5 min.
instead of this I want to do is,apply format cell in which dash will be considered as zero and I will import data by selecting preserve format, so no need to run replacement macro every 5 min.
So pls let me know custom format cell in which positive value ll be consider as positive,negative as negative but dashes as zero
thank you.

In your custom format cell use the following format: #;-#;"-";#
It decomposes as positive numbers; negatives; nul value; any text.
I Commonly use: #,00;-#,00;"-";# to set get 2 digit precision.
Access format cells with right click > Format Cells... > tab Number > Category custom

Related

Convert Text to Time with milliseconds

When I paste a time with milliseconds like this 21:34:58.342 into excel, it does not get converted into time format and is stored as text instead. I've tried converting it manually by means of =--TEXT(A1;"hh:mm:ss.000") but it produces #VALUE! error.
How do I convert time with milliseconds text to time format?
Update
If I paste 21:34:58 the value is converted into Time correctly. If I apply h:mm:ss.000 format to the resulting cell the value is displayed as 21:34:58.000. But if I edit the cell and add a millisecond to the value 21:34:58.001 it becomes Text.
Most likely, your system (see Windows Regional Settings) decimal separator is not a dot. You need to use your system decimal separator when you enter the millisecond value. Most likely, that is a comma. You may need to use your system decimal separator in your format string also.

Converting date from general type to date, 9/29/1986 0:00:00 to dd/MM/YYYY CSV file

i have hit wall after trying INT, TIMEVALUE and all other date formatting on the dates in CSV file.
I was able to change few dates using INT and then change the date format but few dates (highlighted in yellow) i am not able to convert to date format. Originally it is string, which i tried changing to Number and Date type before applying formulas but still its not getting formatted correctly.
i have tried MID/LEFT etc. to extract part of it but when joining these parts using "" & "" converts to text and converting it to date resulted in long ##### output, did tried excel advance option ticking Use 1904 date system.
Any help in right direction is much appreciated. i have not found any duplicate question similar to my format, closest i found didnt have time stamp so that formula didnt work either.
Take a look at your date format. The first digit is either 1 or 2 characters and you need to take that variation into account. the nice thing is based on your data that the days is always 2 digits. this simplifies things a little.
Lets start with the basics and assume your first string of a date is in A2. Let us start simply by striping out the numbers from the text one segment at at time while being generic about the position and number of character. So in order to pull out the number for the month, use the following formula:
=LEFT(A2,FIND("/",A2)-1)
Find will look for the position of the / character in the string and return its number. in this case it should be 2. This means its a single digit month. So we only need to pull 1 digit. In the general sense 1 less than the position of the /.
The next task will be to pull the digits for the day. We can do that using a similar formula. This time lets use MID instead of left. In order to for MID to work, we need to define the starting point. This time the general case of the start point will be the first character after the first /. The other nice part about this is we know the number of characters to pull will always be 2. As such you can use the following formula to pull the month:
=MID(A2,FIND("/",A2)+1,2)
(note if your day digits were not consistently 2 then you would have to measure the number of characters between the two / characters and replace the 2 in the formula with you calculation)
In order to pull the year the process is basically the same as for the month with some minor tweaks. The resulting formula I am suggesting is:
=MID(A2,FIND("/",A2,4)+1,4)
Now the reason I used 4 as the starting position for the find is to make the formula work for the case where days could be a single digit. It the closest the second / can be to the start.
now that you have all that you need to combine it together to make the date. This is where the DATE formula comes into play. It works in the following format: DATE(Year, Month, Day). So now we simply grab each of the individual formula and build the DATE formula which should wind up looking like the following:
=DATE(MID(A2,FIND("/",A2,4)+1,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2))
if you get a date that is just bunch of number format the cell to display the date in the format of your choosing.

Controlling Excel time format input/output

Background: I have been officiating our local jogging events for about ten years now. I am responsible for handling the data of the participants (name, sporting club, bib number) split into their categories (age bracket+gender, distance). The main task is collecting their times, and processing that data (sorting the runners within their category etc). I can handle this with Excel mostly fine.
Problem: What is the ideal time format for entering the race times of the participants? The times are either in the format mm:ss or (for slower runners and/or longer distances) h:mm:ss. Excel doesn't seem to have a built-in format where the hours field is optional. For optimizing my workflow ideally I would like to have a cell format such that the input
47:12 is to be interpreted as 47 minutes and 12 seconds, and the input 1:09:38 is to be interpreted as 1hr 9 minutes and 38 seconds. However, Excel, with the best fitting cell format that I found, will insist that the input 47:12 means 47 hours and 12 minutes. For times exceeding 1 hour I would input 1:03:00 if I meant that the seconds field is to be left with value zero.
How to make Excel realize that when the format can handle up to three numbers as inputs, it would, when given only two numbers, move them towards the end?
Thinking: I "can" key in 47 minutes and 12 seconds as 0:47:12 all right. But because most of the times are under 1 hour, that is partly wasted effort. Also, using such a format the data is displayed on the screen together with that superfluous 0:. What's worse (IIRC) those leading zeros
also appear in the printed versions, which is strange (insulting even) in a shorter distance for junior participants.
My hack: I enter the times as general numbers in the mm,ss format (in these parts a comma serves as a decimal separator). Excel can sort those as numbers just fine. I then duplicate the data of that sorted column to another "printable" version (formatted as text), where the data is just copied, but I correct the times exceeding 60 minutes by hand. This works just fine as long as I'm not in a hurry (our event is not exactly Boston Marathon, say, less than 200 participants), and remember to hide the column that is not supposed to be printed. This is kludgy, and there have been accidents, when other officials have been rushing me to get the results printed.
I managed to create a format where the hour-field is optional. It works with a conditional format. First you format your cells as standard, so you get the times as comma-values. After that you create a conditional format for these cells, which has two rules:
if cellvalue > 0.04166667 format hh:mm:ss
if cellvalue < 0.04166666 format mm:ss
Result:
47:12
01:09:38
01:00:00
So you get what you really want and you can use the original values for sorting and so on.
EDIT:
For the input you need four additional columns. You enter the times as you want, e.g. 47:12 and 1:09:38. In the next three columns you split these values in hour, minute and second, whereby the interpretation limit is 3 hours (03:00), which is 0.125.
So, these are the formulas for the split columns (your input is in B1):
Hours: =IF(B1>0.125,0,HOUR(B1))
Minutes: =IF(B1>0.125,INT(B1)*24+HOUR(B1),MINUTE(B1))
Seconds: =IF(B1>0.125,MINUTE(B1),SECOND(B1))
And finally, you put all values togehter in the forth column:
=TIME(C1,D1,E1)
and use the conditional format above.
If you will be entering your data as
`mmm,ss`
where the comma is the decimal point, then you can convert it to "Excel Time" with the simple formula:
=DOLLARDE(A1,60)/1440
Format the result as you wish.
If you want everything displayed as h:mm:ss then use that as your custom format (Format > Cells > Number > Custom Type:...)
If you want h to be displayed only with values of 60 minutes or greater, then use
[<0.0416666666666667]mm:ss;h:mm:ss
for your cell's custom format.
Beware that seconds must be entered with two digits always. In other words
6,2 will translate to 6 min 20 sec.
6,02 will translate to 6 min 2 sec
I really like IQV's answer above, but as pointed out in the comment section, the leading zero will be required for the data entry side. If for whatever reason this is not acceptable you can use the following ugly formula to convert your time entered in your usual method of mm,ss to hh:mm:ss with the hh: being displayed as required. Unfortunately it converts the whole thing to text which means you can no longer perform math operations on it.
=IF(FIND(".",MOD(D2,60)&".")=2,"0","")&MOD(D2,60)
and since you use , as your decimal separator the formula would become:
IF(FIND(",",MOD(D2,60)&",")=2,"0","")&MOD(D2,60)
If you use ; as your list separator then your formula becomes
IF(FIND(",";MOD(D2;60)&",")=2;"0";"")&MOD(D2;60)
There are probably some cleaner formulas, but that will get you started. Just replace D2 with the location where your time is stored.
Again I still prefer IQV's answer as you can do much more with the time information when its stored as a number and not text.
Option 2
lets say you change your data storage method to hhmm,ss in cell D6. you could rip apart the information and reassemble it in a display friendly version as follows.
=IF(FIND(".",D6)<=3,LEFT(D6,2)&":"&RIGHT(D6,LEN(D6)-FIND(".",D6)),LEFT(D6,FIND(".",D6)-3)&":"&MID(D6,FIND(".",D6)-2,2)&":"&RIGHT(D6,LEN(D6)-FIND(".",D6)))
you will need to substitute your list separator for the , and then substitute a coma for the decimal.

How to format Microsoft Excel data labels without trailing decimal on round values?

(Not sure if this is the best stack for this question).
What is the format to have 14500 read as $14.5K but to have 3000 read as just $3K without the trailing decimal point?
I can't seem to comprehend the correct expression from the manual.
Excel does not appear to support this functionality using custom format codes. However, there is a way to simulate this. Create a new column that uses the function ="$"&A1/1000&"K".
Original ="$"&A1/1000&"K"
$3,500 $3.5K
$3,000 $3K
$14,500 $14.5K
$13,300 $13.3K
$25,000 $25K
$250,000 $250K
To get this to work, I formatted the cell's of the data column 4
4
4
4
3.5
13.5, by either selecting the column and then right click and format cells or by right clicking on the chart and selecting format data labels.
I formatted this with the regular expression $#K so that the data then shows as
$4K
$4K
$4K
$4K
$4K
$14K. The consequence is that the number is rounded to not include the decimal.
Now, all i needed to do was separately format the individual cell's that had decimal values by right clicking on the individual cell's and changing their format to #.0K.
Thus we now have, $4K
$4K
$4K
$4K
$3.5K
$13.5K
Also, the , can be used in the regex ($#,K for round numbers, $#.0,K for decimal) for data of thousands, like my original question.
This was an acceptable solution for me because there were only two such fractional data points.
For a larger dataset, you will need to use a conditional expression to determine all the cell's that have decimal values.
One way to do this, is like so:
If your numbers are in column B, apply this formula for column C
=B1=INT(B1)
This will show TRUE if the data is of INT data type (no decimal precision) and FALSE if not.
Now, select column C and select Data\Filter\Autofilter
From the drop-down list in C1, select FALSE
This will show only the decimal numbers and hide the whole numbers.
And now you can apply the relevent formatting as described above.

Excel 2007: How to display mm:ss format not as a DateTime (e.g. 73:07)?

I need to create and Excel table that computes daily training times. each row has the following fields: Date, Distance, Time and Minutes/Km. My main problem is that I want to display the Time in format of mm:ss. For example: 24 min and 3 sec should be 24:03, but "Excel" turns it to 00:03:00 (3 min after midnight). I've tried setting up "special formatting" but still "Excel insists" on formatting the hours. More over, training may exceed 60 minutes and I still want it only as mm:ss
My second question is after I'm done with the formatting issue, what is the simple way to compute Time/Distance?
enter the values as 0:mm:ss and format as [m]:ss
as this is now in the mins & seconds, simple arithmetic will allow you to calculate your statistics
Excel shows 24:03 as 3 minutes when you format it as time, because 24:03 is the same as 12:03 AM (in military time).
Use General Format to Add Times
Instead of trying to format as Time, use the General Format and the following formula:
=number of minutes + (number of seconds / 60)
Ex: for 24 minutes and 3 seconds:
=24+3/60
This will give you a value of 24.05.
Do this for each time period. Let's say you enter this formula in cells A1 and A2. Then, to get the total sum of elapsed time, use this formula in cell A3:
=INT(A1+A2)+MOD(A1+A2,1)
Convert back to minutes and seconds
If you put =24+3/60 into each cell, you will have a value of 48.1 in cell A3.
Now you need to convert this back to minutes and seconds. Use the following formula in cell A4:
=MOD(A3,1)*60
This takes the decimal portion and multiples it by 60. Remember, we divided by 60 in the beginning, so to convert it back to seconds we need to multiply.
You could have also done this separately, i.e. in cell A3 use this formula:
=INT(A1+A2)
and this formula in cell A4:
=MOD(A1+A2,1)*60
Here's a screenshot showing the final formulas:
To make life easier when entering multiple dates/times it is possible to use a custom format to remove the need to enter the colon, and the leading "hour" 0. This however requires a second field for the numerical date to be stored, as the displayed date from the custom format is in base 10.
Displaying a number as a time (no need to enter colons, but no time conversion)
For displaying the times on the sheet, and for entering them without having to type the colon set the cell format to custom and use:
0/:00
Then enter your time. For example, if you wanted to enter 62:30, then you would simply type 6230 and your custom format would visually insert a colon 2 decimal points from the right.
If you only need to display the times, stop here.
Converting number to time
If you need to be able to calculate with the times, you will need to convert them from base 10 into the time format.
This can be done with the following formula (change A2 to the relevant cell reference):
=TIME(0,TRUNC(A2/100),MOD(A2,100))
=TIME starts the number to time conversion
We don't need hours, so enter 0, at the beginning of the formula, as the format is always hh,mm,ss (to display hours and minutes instead of minutes and seconds, place the 0 at the end of the formula).
For the minutes, TRUNC(A2/100), discards the rightmost 2 digits.
For the seconds, MOD(A2,100) keeps the rightmost 2 digits and discards everything to the left.
The above formula was found and adapted from this article:
PC Mag.com - Easy Date and Time Entry in Excel
Alternatively, you could skip the 0/:00 custom formatting, and just enter your time in a cell to be referenced of the edge of the visible workspace or on another sheet as you would for the custom formatting (ie: 6230 for 62:30)
Then change the display format of the cells with the formula to [m]:ss as #Sean Chessire suggested.
Here is a screen shot to show what I mean.
If you are using hand inputted data, you can enter your data as mm:ss,0 or mm:ss.0 depending on your language/region selection instead of 00:mm:ss.
You need to specify your cell format as [m]:ss if you like to see all minutes seconds format instead of hours minutes seconds format.
as text:
=CONCATENATE(TEXT(cell;"d");" days ";TEXT(cell;"t");" hours ";MID(TEXT(cell;"hh:mm:ss");4;2);" minutes ";TEXT(cell;"s");" seconds")
5.In the Format Cells box, click Custom in the Category list.
6.In the Type box, at the top of the list of formats, type [h]:mm;# and then click OK. (That’s a colon after [h], and a semicolon after mm.)
YOu can then add hours. The format will be in the Type list the next time you need it.
From MS, works well.
http://office.microsoft.com/en-us/excel-help/add-or-subtract-time-HA102809662.aspx
One convenient trick to entering elapsed times into Excel is to have two zeros and a colon before the number of minutes, details follow. For copy and paste operations into Excel without have to worry about formatting at all one can use the format 00:XX:XX where XX are two digits totaling < 60. In that case, Excel will echo 0:XX:XX in the cell contents displayed and store the data as 12:XX:XX AM. If one pastes data in a 00:XXX:XX format into Excel, or 00:XX:XX where either XX > 59 this will be converted into a fraction of a day.
For example, 00:121:12 becomes 0.0841666666666667, which if multiplied by the number of seconds in a day, 86,400, becomes 7272 s. Next, 00:21:12 would by default show 0:21:12 stored as 12:21:12 AM. Finally, 00:21:60 becomes 0.0152777777777778, also a fraction of a day.
This suggestion is made merely to avoid having to worry about specific formatting in Excel, and letting the program worry about it. Note, for Excel data internally formatted as 12:XX:XX AM one can only use certain Excel commands, for example, one can take an average. However, subtraction will only work when the result is a positive number. Such that converting times into seconds, fractions of a day, or other real number is suggested for access to more complete arithmetic operation coverage.
For example, if one has a column of mixed time formats, or times that are negative and will not display, if one changes the number formatting to General, all the times will be converted to fractions of a day.

Resources