I want to ask a very simple and maybe for some it may sound silly.
One person told that while copying and pasting in Excel you should use Paste Special and paste formats first and then values, then it keeps any leading zeros or else they will be removed. But someone else told other way round i.e. first values and then formats. I didn't notice any change also if I pasted as it is after copying.
So please tell me if these people are true and if yes which exactly is the correct order?
Oh, the joy of Excel conversions. You have to be cautious with your different circumstances.
Time to have some fun. Try this:
In cell A1 format the data as Text and enter the value 010.
In cell A2 leave the format as general and enter as 010.
Now go to the immediate window in VBIDE and execute the following:
? Typename(Range("A1").Value)
? Typename(Range("A2").Value)
A1 is a string, and A2 is a double.
If you change the format of A1 now to General then again type:
? Typename(Range("A1").Value)
It is still string - AND it still has the leading 0 at the front!
HOWEVER: now execute the following:
range("A1").Value = range("A1").Value
Although this looks like a pointless command - its effectively updates the cell by using VBA. Excel will now do the conversion to a double!!
? Typename(Range("A1").Value)
This is now a double.
So altering the format after the data can result in different data because Excel is doing a clever conversion. But this is dependant on the cell being updated. Just changing the cell format might change that value, but not necessarily - and later it could change if a user presses F2 and enter on the cell. Lovely - thank you excel for being intelligent.
Don't even get me started with other conversions.
So, I suggest that in the majority of cases, you should actually format first and data after.
Happy pasting! :)
Cell value and cell format are two distinct properties of a cell in Excel.
For displaying values, excel applies the format of the cell to its value. So if your cell holds a number and the format specifies that the number should have leading zeros, the number will be displayed with a leading zero. This does not change the underlying value!
The format affects only the display.
As an example:
Let's say your cell holds the value 5.5 as numerical value. Applying the format 0.00 will display that value as 5.50. Applying the format 0.00 min will display the same value as 5.50 min. But the value itself is still unchanged 5.5 - this way, you can e.g. be very specific about how you want to display a number, but still use its plain value for calculations. Same principles apply to every other formatting rule and data type of course.
So no matter which way round you paste - as long as the cells end up with the correct combination of value and format, you will end up with the correct result.
Related
Hey guys I have a situation where I need to format a column to display APR(%) values in a certain way. Basically the values should be formatted like below:
Raw input Formatted value
========= ===============
0 0
0.0 0
4.4566 4.5
5.00 5
6 6
6.4 6.4
I tried creating this formula below but for some reason it doesn't round the number to 2 decimal places.
=INT(ROUND(A1,1)*100)/100
What am I doing wrong? Or is there a better way to handle this?
UPDATE: So I am applying the function to the same cell as the number is in. For instance the A1 cell contains 4.566 value and I applied the function to that same cell and this doesn't seem to be working for Excel. Any other ways to do this?
P.S: Im using the MS Excel for Mac
Two steps
Format the cells to Number with one decimal place
Conditionally format the cells to a Number Format of General if the value is an integer
EDIT: Since you cannot conditionally format the number format in Excel for MAC, there are several workarounds.
If you do not mind changing the actual value, add a column which you will use to display the result. Format the Column as "General", and use this formula (assuming your "real data" is in column A:
=IF(A1<>INT(A1),ROUND(A1,1),A1)
Other options that may work would include using an event-triggered macro (if that can be done in Excel for Mac); and possibly you can create the worksheet in Excel for Windows and the conditional format might be recognized in Excel for Mac, even if you can't create it there.
As explained in the documentation here,
Suppose that cell A1 contains 823.7825.
...
=ROUND(A1,2) ... equals 823.78
You should be able to therefore apply this to your entire column to get the precision that you are after.
Rather than using =INT(<another_cell_value>*100)/100 to derive the format you want, simply specify a custom format with the following:
#,###.##
This way, you only get the number of decimal places that you specified in the ROUND function.
I have a spreadsheet with numerous formats, mostly time and whole number. Data validation is present to assure proper formats. certain fields can be selected and VBA programmatically inserts the system time to the selected cell. This works perfectly and is very helpful when using this sheet. The problem occurs if a cell that should have a whole number (and definitely not a time) is accidently selected, then the "enter system time" code is run. This changes the format of that cell to time/date. said in another way, A1 is formatted for Number, 0 decimal places. A1 is selected and the "Enter system time" macro is run. The macro is not affected by the data validation rule that would otherwise prohibit anything but a whole number between 1 and 999. Now that the formatting is changed by VBA (somehow), when you enter, say, 5 into that (formerly) number-formatted cell, displayed is 1/5/1900 0:00. Because this is a compiled workbook, the change is permanent; the cell format cannot be changed back.
so, my question is: Is there a workaround? Is there a way to prevent this sort of format change? is there a way to unlock the cell if the format is wrong? Is there any sort of suggested method to avoid this?
You can check if the format is a number with 0 decimal places using the NumberFormat property of the Range object like:
If Range("A1").NumberFormat = "0" Then
'Some Code
End If
Check https://msdn.microsoft.com/pt-br/library/office/ff196401.aspx for more information on formats
Finally got this. The correct number formatting command is:
If Selection.NumberFormat = "[$-409]h:mm AM/PM;#" Then...
I'm looking to format excel cells such that whatever number I put in is the value it displays. i.e. at the moment when typing in 0.69374767047, the value it reads as is 0.69374767. But I also have numbers like; 0.00305 which come out correctly. Is there a way to format the cell so whatever number I put will come out to the correct decimal place and also that there is no 0s on the end of the number, as I need to do things later with that. Any help would be greatly appreciated.
Actually you can do it without code, just custom cell format and put 0.,### so it will give at least an integer and any dp if needed.
e.g.
Input Output
12 12
4.305 4.305
3.2 3.2
In Excel, I have a cell value as number format, say 10/2. It displays as 10/2 but I would like 5.00.
It evaluates to 5.00 if I add an = before it i.e, =10/2, but I don't want to have to edit around 500 rows of that column.
I tried to use VALUE function but it evaluates it to 42279.00:
Cell B1 10/2
Cell B2 42279.00
Another data example is: 100/20.
Can you please tell me what has gone wrong, or is there any approach to get the cell value 10/2 to be evaluated to 5.00?
Please try applying a formula of the following kind to all your data:
=MONTH(B1)/DAY(B1)
Having done so you may select the results, Copy and Paste Special over their source (assumed to be ColumnB) and then delete the formulae.
Excel has, trying to be helpful, interpreted your entries as dates - the above should reverse the coercion.
Since now it seems not all entries have been coerced into dates, I suggest for those that have not:
=LEFT(B1,FIND("/",B1)-1)/MID(B1,FIND("/",B1)+1,LEN(B1))
The problem is that you’re putting in what you’re thinking of as a calculation (ten divided by 2), but you’re not saying it’s a calculation (no “=”) so excel is looking at it as a value. When it looks at “10/2” it thinks “that’s a date, October second!” and it treats it as a date.
Dates are actually kept as numbers. If you had the column formatted as date or general, it could display as a date. But I’m guessing you have the column formatted as a number so it’s giving you the numeric representation of October 2, 2015.
The bad news is that as far as I know you would have to get the “=” in somehow, or do the calculation and replace it with 5 (10 divided by two would never be other than 5. If the latter you could select the column and do a replace 42279 with 5.
Is there a way to add a leading zero to a date that is 7 digits and should be 8?
7301982 should be 07301982.
I have a column full of these values, and need a way to do so with a formula. Any ideas?
I know this is an oldie, but when I googled for a solution this was the first result.
What I did was:
=concatenate(year(A1),text(month(A1),"00"),text(day(A1),"00"))
Where A1 is a date field.
=text(A1, "00000000") will do it.
Set a custom format of 00000000
Just another thought since this just happened on my new laptop. It could be your windows settings. If you prefer leading zeroes on the month everywhere in windows (like the lower right hand clock) then you can:
Control Panel >> Clock, etc >> Change Date, Time or Number Formats... then set the Short Date to MM/dd/yyyy.
This also carries over to Excel as the first date format. I know it is not a formula exactly as asked, but this is the article I found while searching.
Simply go to custom for the format of the number and select yyyy\m\d and add more m or d to it.
This is a good formula when you need leading zeros so another application sees a 9 digit number.
Add a column to your spreadsheet (Column B if your data is in Column A)
Use this formula in the new column: =REPT(0,9-LEN(A2))&A2&""
Get the 1st cell, then drag down as much as you need.
Remember to copy/paste option 123 to save as data. Otherwise, you'll see data but in reality it is a formula and you will receive reference errors if you try to use the data in column B.
9 digits and column B are variables. You can use any length or any column on your spreadsheet. Just adjust the formula.
Copied from another answer on a different site, worked for my like a charm!
ok. It seems that your dates are formatted as text. This is what you should do.
first, on a blank cell somewhere on the sheet, type the number 1. then, right click, copy.
next, highlight the entire column of dates. right click, paste special, multiply.
all of the dates will have turned into numbers.
next, highlight the date column, and apply the date format that you want.
There is a simple way to maintain the leading zeroes in Excel.
Simply add this to the cell and type whatever value you need and the zeroes will be retained
For ex: If I want 0000000023
Type into a cell '0000000023
That ' symbol seems to retain the zeroes as long as you type it before the values.
This date format MM/DD/YYYY is available if you select the Locale (location): English (Philippines). Try it with one cell and then copy/paste/special/formats the others.