Formatting cells in excel - excel

I have excel sheets with thousands rows and columns of numeric data, and need to do some calculations on this data. But in few files there is a cell or two which have their format as text even when they contain a number. The data is so huge that it is not possible to check each and every cell for the format. So is there a way I could rectify these errors?

If you are using Excell 2007 or later, use search and replace.
Leave Find What and Replace with blank, select Text in the find what format, and General (or other numeric format) in the replace with format.
Run Replace All and its done!

Use ASAP utilities www.asap-utilities.com/
They have macro to turn text into numbers
You could also use the value function
=value(A1)
Which converts text to numbers

I would start by selecting the particular row/column headers you wish to have formatted as numbers. Then, just choose "Number" from the drop down menu that allows you to select the cell type. This will apply the format the all value cells in that particular row/column.
This is of course assuming that all cells read as text will be valid numbers. Otherwise, you'll have to employ additional functionality.

Or, copy the values to a new worksheet, but before it, you need format all cells to number format and use the "Paste Special" option, choosing the "Values" dialog options.

If you don't have any formulas, just values, you could run this code
Sub MakeValues()
ActiveSheet.UsedRange.NumberFormat = "General"
ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
End Sub

Related

Number value as text

I have a single cell with the value:
426,427,433,439,442
This isn't a number, rather a list of numbers. If I try to add another number to the list, for example, 679. Excel changes the cell to read:
679,426,427,433,439,000
If I select the cell and format it as "text", it changes to:
4.26427E+14
I've tried various cell formatting options, but I can't seem to get Excel to treat these numbers like text.
Copy and paste the column into Notepad, format a new column in Excel as text. In Notepad select all, copy it back out from Notepad into the column in Excel that you formatted for text.
First place a single quote (apostrophe) in front of the set of numbers and add the latest value at the end appropriate position.
add (apostrophe) in front of numbers
add (comma's) between
add any number by adding a (comma)
Possibly:
=LEFT(A1,3)&","&MID(A1,4,3)&","&MID(A1,7,3)&","&MID(A1,10,3)&","&MID(A1,13,3)
It seems you have a number 426427433439442 with the commas purely a presentational aspect of the formatting. I take it you want the commas and the only way now may be to insert them.

How to remove the first letter in each cell in a column in excel?

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 .

Force Excel 2007 to treat all values in a column as text

I have a large column of data in Excel. This data should all be treated as text, but in some cells Excel is "magically" changing the data to numeric. This is screwing up my vlookpup() functions in another part of the spreadsheet, and I need to override Excel's automatic data type detection.
If I manually go through the cells, and append ' to each numeric cell, it works. I just don't want to do this by hand for several thousand cells.
For example, this works:
Manually type '209
And this does not work:
Manually type 209, right click and format as text.
If changing the format of the column is not an option, it's helpful sometimes to create another column that's 'vlookup friendly' and leave your main column alone.
This is a trick I've used a few times:
Say your 'mixed' column is column A.
In column B, enter the formula:
=CONCATENATE(A1)
or as Jean-François pointed out in a comment, the shorter version:
=A1 & ""
And drag it down for to the bottom row.
Column B will be all strings. The VLookup can then use column B.
Under the Data Tab, open the Text to Columns wizard and set the Column data format to Text. The destination cell can be set to the original data cell, but it will replace the original formatting with text formatting. Other aspects of formatting e.g. Bold, color, font, etc. are not changed using this method.
Setting the cells to "Text" format, as Jean mentioned, should work. The easiest way to do this, in any version of Excel, is:
Right-click cell, "Format Cells", "Number" tab, select "Text" format.
Have you tried setting the cells' number format to "Text"?
In Excel 2003: Format > Cells... > Number > Category: Text.
I don't have the more recent Excel versions, but it has to be something similar.
I tried all the above but didn't work. And then added an apostrophe before the number. Only then it changed to text from the exponential notation.
If you already have your data and manually adding a quote in front of your data in each cell is not an option you can use a helper column and write
="'"&A1
in B1, where A1 is the reference to your cell, and drag down the formula in B1 to the bottom. At this point you will see the quote, and you need to paste data in column B as values (CTRL+C & ALT+E+S and select values, or paste special as values from the top menu). Then find+replace a '(quote) with a '(quote) and you will have a column with values forced to text and a quote in front of each numeral representation of the number.
Updated for Office 365 / Excel 365:
CONCATENATE is being deprecated and replaced by CONCAT.
This method still works, i.e. I need 7E10 to appear as 7E10 and not 7.00E+10
Microsoft documentation source here.

Convert to date

How i can convert number 20020415 to date 15.04.2002. I am working in Microsoft Excel 2003?
Thanks!
If your numbers are always in the same format (i.e. yyyymmdd) then use Excel's Date function to convert your number to a date:
For example, assuming date 20020415 is in cell A1, then in cell B1 use:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
This will make sure your number is of a date format which will make it easier to use in the future if you want to treat it like a date.
Then, using Format > Cells, select 'Date' and select the appropriate formatting option (in your case 15.04.2002).
As an aside, you can access the 'Format Cells' dialog box using the shortcut keys CTRL+1. I find this a highly useful shortcut to know.
If A1 contains a number instead of text, you can use this:
=DATE(INT(A1/10000),INT((A1-10000*INT(A1/10000))/100),A1-(100*INT(A1/100)))
This can then be formatted using Excel formatting options.
Let cell A1 contains the text 20020415.
=CONCATENATE(RIGHT(A1, 2), ".", MID(A1,5,2), ".", LEFT(A1, 4))
will produce 15.04.2002.
Afterward, if you want to store the value and not the formula you can copy and paste the value only.
Note: this method still keeps the date as text.

Web scraping in VBA and Excel

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".

Resources