I have a series of spreadsheets filled by farmers that list the composition of NPK fertiliser applied to their fields.
In some of these something happened with the cell format (that was originally set to text) and now the fertiliser composition is read by Excel as a date.
Example of text entered in the cell (N:P:K):
25:00:14
Excel now reads this as:
01/01/1900 01:00:14
When looking at the cell, I see the correct value (25:00:14). However, when importing the data into Python, or when copying the value to a different cell, the date (01/01/1900 01:00:14) gets exported instead.
I have tried: changing the cell type to text, copying the contents of the cell into another cell set as text, replacing ':' with a different special character. Nothing along these lines seems to work.
I have a few hundreds of these entries, so any ideas on how to avoid having to re-enter them manually would be greatly appreciated!
Related
I am working in Excel and I am wanting to find out if there are matches in one sheet based on a list in the other sheet.
I have pasted the values in a list and want to return their corresponding value from another sheet. The cells that contain letters and numbers work correctly (example: D5765000), but for some reason if the cell has only numbers, Excel is not able to find it in the other sheet, even though it exists.
I pasted a value 745‐3000 in the list and I am looking for this corresponding value in another sheet. It shows as #N/A on the lookup indicating it doesn't exist in the other sheet. However, if I delete the 745‐3000 and manually type 745-3000, then Excel somehow does recognize the value and find it in the other sheet.
The formatting is exactly the same in both and there are no spaces in either list. I cannot understand why Excel won't recognize the pasted value of 745-3000. Any ideas?
Excel is reading the "-" with a different code than it is with a manually typed "-"
Isolate the "-" and use to find and replace. Does some data contain multiple offending "-"'s?
=REPLACE(H4,FIND(G4,H4),1,"-")
EDIT: Switched from code to Unicode
TY #ron
We find the offending char using the set up pictured below:
Some of the formulas used:
Yellow Cells:
=UNICODE(MID($A$3,C4,1))
Light Blue Cells:
=UNICODE(MID($E$3,C4,1))
At the bottom we check to see what code we get from the value. I get a VALUE mark with from the unicode value of "-"
I'm getting a #DIV/0 when calculating the average time from a range of cells.
A copy of the file can be found here;
http://www44.zippyshare.com/v/5ZlxD44N/file.html
I have literally no idea why this is happening, nor can I seem to find a way around this.
I have checked the formatting of the cells, tried to re save the file, pull the data on to a new page. Nothing seems to work.
Any help is much appreciated.
All the data in A1:C10 is stored as text (by default text is left alligned and cell's display doesn't change when you change formatting). To convert it to time values:
enter 1 in any empty cell
copy this cell
select A1:C10, choose Paste special->Multiply
format the range back to time format
Your sheet is set to manual calculation, so make sure to recalculate the sheet with F9 or switch it to automatic.
Alternatively you can convert text to time inside array formula (confirmed with Ctrl+Shift+Enter):
=AVERAGE(A1:A10*1)
I've been trying to understand excel cells more and specifically their data types. If anyone is interested in the detail my investigation is in the numbered points below. My conclusions are labelled A to D. I'm really interested in whether anyone has anything to add.
A. Each excel cell has a property that defines the expected "data type" of the data that it will store. The data value stored in a cell also has a "data type" property, that does not have to be the same the the cell "data type" property. (Data types are General, Text or Date). (The Cell's data type is not the same as the cells formating set using "Format Cell">"Number tab" "format category" but it is related
B. When data is entered into a cell, the data type given to the the data value is inherited from the cell's data type (when the data value can be converted into the cell data type). If the data contains a ' character at the start, it causes the text data type to be allocated as the value's data type, regardless of the cells data type.
C. When you use excel copy>Paste(Values Only) to copy the data value from one cell to another, the data type is also copied. (This is a bit nuts as there is no override to this in paste special. You could kind of do with a PasteSpecial>Raw option)
Note: If you paste data in from a text document (eg 01234), using the default paste will cause the text 0123 to be converted into a number. Using Value Only paste, the 01234 is pasted a a value with data type of text - if th cell's data type is text.
D. Entering =SUM(1,2) into a cell with a text data type causes the formula to be displayed and not calculated. ie it is treated as text data.
Note that this VBA function can be used to convert the data type of a number value stored in a cell to have the text data type with the same characters. Simply reference the cell you want to convert with the formula. Yu can use copy>paste special(Values Only) to move the converted value into a cell so it's then stored as a value.
Public Function ConvertValueToHaveTextDataType(Avalue As Variant) As String
ConvertValueToHaveTextDataType = CStr(Avalue)
End Function
Here's why I came to these conclusions.
I've been experimenting and found:
Loading data into worksheet cells using QueryTables.TextFileColumnDataTypes has a parameter TextFileColumnDataTypes which can be assigned xlTextFormat, xlGeneralFormat and some date formats. There is no numeric option. So using the xlGeneralFormat to load numeric data seems to be "how it's done".
Based on this I assume each Excel cell has a "data type" (ie General, text or date).
"Format Cells" will change how data is displayed, but also changes how they behave when data is being input ie changing the cell format can also change a cells "data type". When a cell format is TEXT, entering "01234" will cause entered data to be stored as text and the leading "0" is kept. When a cell has GENERAL format entering "0123" will cause it to be stored as the number 123 (ie note the 0 is removed).
Consider a cell with TEXT format and "0123" stored as a text value. Changing the format of the cell to GENERAL or NUMBER will not change the characters stored in the cell, but will add a green tag to the cell that provides a "popup warning" that informs you "Number Stored as Text". (Paste special,multiply can be used to convert these to a number)
This is where it gets weird.
If you edit the text value "0123" stored in a "General format cell" on pressing the ENTER key the "0" is removed and it become 123, which is what you would expect. However if you, copy the "0123" cell and paste it using the "VALUE ONLY" option, the data is pasted as "0123", the same thing happens if you paste this into a number Format cell. So when you use excel copy>Paste(Values Only) to copy the data value, the data type is also copied. (This is nuts!).
If you paste 123.12 stored as number from a numeric or general format cell, into a text format cell the value remains as 123.12 and the cell type remains as text, no popup warning is shown, I'm not sure what the data type of the value is. However if you edit the cell and press RETURN to enter 123.12, you do get a warning tag and popup saying "number stored as text"
As a further complication if you want to enter a number 0123 into a cell with NUMERIC format, and have it stored a text "0123" you can enter it as '0123 the ' indicates that excel should store the value with a data type of text.
This is useful.
Note that if you were to use LEFT({acell stroing '0123},1) it would return "0". Which is ok. Also note that, if you copy and paste (values only) a numeric format cell storing '0123 into a general format cell, the ' is no longer displayed for the cell and you get a green popup warning "number stored as text". Which is Ok, but worth being aware of.
The formula =TEXT("123","0###") creates a value with a text data type. If you copy and paste the result, it becomes a data value with the text data type.
The formula T is useful as it can be used to find whether the data type of a value stored in a cell is TEXT or not. =T(0123) = "" =T("0123") = 0123
If you reference a cell in a formula that adds 1 to the cell value, the cell data type and the data type of the value make no difference to the calculation. The data value is converts to be a number a necessary, implicitly.
As you would expect, when pasting data into cells, if you choose to match the destination formatting and the cells you are pasting the data into uses the TEXT format, any data with leading "0"'s will have the 0's kept.
Did anyone read this far?
If you want to show preceding zeroes on a number, providing you have a fixed number of digits before the decimal point you can Custom format the cells as e.g. '0000.00'.
This example will always show four digits before the decimal point and two afterwards; it has its limits but is very useful for e.g. product codes. if you standardise on 7-digit codes, set the custom format as '0000000' and '0001234' will stay correct (not '1234') and still be recognised as a number.
I have column in excel like below,
'04-Feb-01
'04-Mar-01
'08-Apr-01
'06-May-01
'03-Jun-01
'08-Jul-01
'05-Aug-01
I want to remove the character ' in all cells how can i do that?
I already tried with =RIGHT(A1,LEN(A1)-1) this one.. not working
Convert the text to a date using DATEVALUE. Then apply a date format to your liking.
When you enter data into a cell, Excel will try and convert it to the correct type (is it text, a number or a date) The single quote is Excel's way of saying treat what follows as text. It comes in handy when entering things like telephone numbers which Excel might think is a number and would not display leading zeros. In your the example the actual value in the cell is the text without the single quote, you can check this by copying a cell and then pasting into notepad and there would be no quote in the result.
Why do you want to remove the quote? If it is because you want the cells to contain a date rather than text you can convert it using the DATEVALUE function or by using copy and paste special values only .
I'm looking to download data tables from websites into Excel and pull specific pieces of data into a separate worksheet to create a database. I'm having trouble parsing numbers that are imported into one cell in Excel. For example, the numbers "-7 -110" written exactly like that on the website are inputted into one cell in Excel as "=-7-110" yielding the cell contents "-117". When the cell is highlighted, the original =-7-110 displays in the formula bar but I do not know how to either a) input the data as-is and turn-off the autoformatting by excel or b) grab the specific cell contents without the formula being formed from the cell.
Any help is appreciated - thanks!
Jason
Microsoft offers three methods to counter-act built-in number formatting:
Avoiding Automatic Number Formatting
If you want to type a value such as
10e5, 1 p, or 1-2, and you do not want
the value to be converted to a
built-in number format, type the
number as a text value. To type a
number as a text value, use any of the
appropriate methods below.
Method 1
Place a space at the beginning of the entry.
NOTE: This method does not work if the entry resembles a number formatted in scientific notation. For example, typing 1e9 results in a scientific number.
Method 2
Select a range of cells, and then click Cells on the Format menu.
Click the Number tab.
Click Text, and then click OK.
This method allows you to type data in the selected cells as text. You must perform these steps before you type the numbers in the cells.
Method 3
Precede the entry with an apostrophe.
For example, type the following: '1 p
Adam has covered the options if you're making changes within the workbook.
Of course, you can also prepare the area into which the data is being imported directly from VBA using the
.NumberFormat
property.
To set the NumberFormat property of a range or cell/s to "Text" you can use
.NumberFormat="#"
For example
Range("C:C").NumberFormat = "#"
will convert all cells in column C to "Text" format.
As far as retrieving the "-7-110" if it's entered into a cell with general format (and is displaying the result of the formula i.e -117), you can access the
.Formula
property of the cell.
For example, if the above formula was entered into cell C1, the VBA code below
Range("C1").Formula
or equivalently
Cells(1, 3).Formula
would return the string "=-7-110".