Excel convert numbers to columns

Convert numbers stored as text to numbers

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel Web App Excel 2010 Excel 2007 Excel for Mac 2011 Excel Starter 2010 More…Less

Numbers that are stored as text can cause unexpected results, like an uncalculated formula showing instead of a result. Most of the time, Excel will recognize this and you’ll see an alert next to the cell where numbers are being stored as text. If you see the alert, select the cells, and then click Excel Error Alert button to choose a convert option. 

Check out Format numbers to learn more about formatting numbers and text in Excel.

Cells with numbers stored as text with green triangles

If the alert button is not available, do the following:

1. Select a column

Selected column

Select a column with this problem. If you don’t want to convert the whole column, you can select one or more cells instead. Just be sure the cells you select are in the same column, otherwise this process won’t work. (See «Other ways to convert» below if you have this problem in more than one column.)

2. Click this button

Data tab, Text to Columns button

The Text to Columns button is typically used for splitting a column, but it can also be used to convert a single column of text to numbers. On the Data tab, click Text to Columns.

3. Click Apply

The rest of the Text to Columns wizard steps are best for splitting a column. Since you’re just converting text in a column, you can click Finish right away, and Excel will convert the cells.

4. Set the format

Currency format selected

Press CTRL + 1 (or Image of the MAC Command button icon + 1 on the Mac). Then select any format.

Note: If you still see formulas that are not showing as numeric results, then you may have Show Formulas turned on. Go to the Formulas tab and make sure Show Formulas is turned off.

Other ways to convert:

You can use the VALUE function to return just the numeric value of the text.

1. Insert a new column

New column next to text numbers

Insert a new column next to the cells with text. In this example, column E contains the text stored as numbers. Column F is the new column.

2. Use the VALUE function

Cell F23 with formula: =VALUE(E23) and result of 107.71

In one of the cells of the new column, type =VALUE() and inside the parentheses, type a cell reference that contains text stored as numbers. In this example it’s cell E23.

3. Rest your cursor here

Cursor resting on lower-right corner of cell

Now you’ll fill the cell’s formula down, into the other cells. If you’ve never done this before, here’s how to do it: Rest your cursor on the lower-right corner of the cell until it changes to a plus sign.

4. Click and drag down

Cursor dragged down, cells filled with formula

Click and drag down to fill the formula to the other cells. After that’s done, you can use this new column, or you can copy and paste these new values to the original column. Here’s how to do that: Select the cells with the new formula. Press CTRL + C. Click the first cell of the original column. Then on the Home tab, click the arrow below Paste, and then click Paste Special > Values.

If the steps above didn’t work, you can use this method, which can be used if you’re trying to convert more than one column of text.

  1. Select a blank cell that doesn’t have this problem, type the number 1 into it, and then press Enter.

  2. Press CTRL + C to copy the cell.

  3. Select the cells that have numbers stored as text.

  4. On the Home tab, click Paste > Paste Special.

  5. Click Multiply, and then click OK. Excel multiplies each cell by 1, and in doing so, converts the text to numbers.

  6. Press CTRL + 1 (or Image of the MAC Command button icon + 1 on the Mac). Then select any format.

Connect with an expert. Learn from live instructors.

Related topics

Replace a formula with its result

Top ten ways to clean your data

CLEAN function

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Although there are already a bunch of valid answers1, none get into the theory behind it.

Excel column names are bijective base-26 representations of their number. This is quite different than an ordinary base 26 (there is no leading zero), and I really recommend reading the Wikipedia entry to grasp the differences. For example, the decimal value 702 (decomposed in 26*26 + 26) is represented in «ordinary» base 26 by 110 (i.e. 1x26^2 + 1x26^1 + 0x26^0) and in bijective base-26 by ZZ (i.e. 26x26^1 + 26x26^0).

Differences aside, bijective numeration is a positional notation, and as such we can perform conversions using an iterative (or recursive) algorithm which on each iteration finds the digit of the next position (similarly to an ordinary base conversion algorithm).

The general formula to get the digit at the last position (the one indexed 0) of the bijective base-k representation of a decimal number m is (f being the ceiling function minus 1):

m - (f(m / k) * k)

The digit at the next position (i.e. the one indexed 1) is found by applying the same formula to the result of f(m / k). We know that for the last digit (i.e. the one with the highest index) f(m / k) is 0.

This forms the basis for an iteration that finds each successive digit in bijective base-k of a decimal number. In pseudo-code it would look like this (digit() maps a decimal integer to its representation in the bijective base — e.g. digit(1) would return A in bijective base-26):

fun conv(m)
    q = f(m / k)
    a = m - (q * k)
    if (q == 0)
        return digit(a)
    else
        return conv(q) + digit(a);

So we can translate this to C#2 to get a generic3 «conversion to bijective base-k» ToBijective() routine:

class BijectiveNumeration {
    private int baseK;
    private Func<int, char> getDigit;
    public BijectiveNumeration(int baseK, Func<int, char> getDigit) {
        this.baseK = baseK;
        this.getDigit = getDigit;
    }

    public string ToBijective(double decimalValue) {
        double q = f(decimalValue / baseK);
        double a = decimalValue - (q * baseK);
        return ((q > 0) ? ToBijective(q) : "") + getDigit((int)a);
    }

    private static double f(double i) {
        return (Math.Ceiling(i) - 1);
    }
}

Now for conversion to bijective base-26 (our «Excel column name» use case):

static void Main(string[] args)
{
    BijectiveNumeration bijBase26 = new BijectiveNumeration(
        26,
        (value) => Convert.ToChar('A' + (value - 1))
    );

    Console.WriteLine(bijBase26.ToBijective(1));     // prints "A"
    Console.WriteLine(bijBase26.ToBijective(26));    // prints "Z"
    Console.WriteLine(bijBase26.ToBijective(27));    // prints "AA"
    Console.WriteLine(bijBase26.ToBijective(702));   // prints "ZZ"
    Console.WriteLine(bijBase26.ToBijective(16384)); // prints "XFD"
}

Excel’s maximum column index is 16384 / XFD, but this code will convert any positive number.

As an added bonus, we can now easily convert to any bijective base. For example for bijective base-10:

static void Main(string[] args)
{
    BijectiveNumeration bijBase10 = new BijectiveNumeration(
        10,
        (value) => value < 10 ? Convert.ToChar('0'+value) : 'A'
    );

    Console.WriteLine(bijBase10.ToBijective(1));     // prints "1"
    Console.WriteLine(bijBase10.ToBijective(10));    // prints "A"
    Console.WriteLine(bijBase10.ToBijective(123));   // prints "123"
    Console.WriteLine(bijBase10.ToBijective(20));    // prints "1A"
    Console.WriteLine(bijBase10.ToBijective(100));   // prints "9A"
    Console.WriteLine(bijBase10.ToBijective(101));   // prints "A1"
    Console.WriteLine(bijBase10.ToBijective(2010));  // prints "19AA"
}

1 This generic answer can eventually be reduced to the other, correct, specific answers, but I find it hard to fully grasp the logic of the solutions without the formal theory behind bijective numeration in general. It also proves its correctness nicely. Additionally, several similar questions link back to this one, some being language-agnostic or more generic. That’s why I thought the addition of this answer was warranted, and that this question was a good place to put it.

2 C# disclaimer: I implemented an example in C# because this is what is asked here, but I have never learned nor used the language. I have verified it does compile and run, but please adapt it to fit the language best practices / general conventions, if necessary.

3 This example only aims to be correct and understandable ; it could and should be optimized would performance matter (e.g. with tail-recursion — but that seems to require trampolining in C#), and made safer (e.g. by validating parameters).

Given a positive number, convert the number to the corresponding Excel column name.

For example, the following image shows numbers corresponding to Excel columns:

 
Excel column number to name

Practice this problem

 
The main trick in this problem lies in handling the boundary cases, such as the number 26 corresponds to column Z, and the number 27 corresponds to column AA. Similarly, the number 1014 corresponds to column ALZ, and the number 1015 corresponds to column AMA.

Following is the C++, Java, and Python program that handles all these cases beautifully:

C++

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

#include <iostream>

#include <string>

#include <cstdlib>

#include <ctime>

using namespace std;

// Function to convert a given number to an Excel column

string getColumnName(int n)

{

    // initialize output string as empty

    string result = «»;

    while (n > 0)

    {

        // find the index of the next letter and concatenate the letter

        // to the solution

        // here index 0 corresponds to ‘A’, and 25 corresponds to ‘Z’

        int index = (n 1) % 26;

        result = char(index + ‘A’) + result;

        n = (n 1) / 26;

    }

    return result;

}

int main()

{

    // seed for random input

    srand(time(NULL));

    // generate column names for 10 random numbers between 1–1000

    for (int i = 1; i <= 10; i++)

    {

        int r = rand() % 1000 + 1;

        cout << r << » — « << getColumnName(r) << endl;

    }

    return 0;

}

Download  Run Code

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

import java.util.Random;

class Main

{

    // Function to convert a given number to an Excel column

    public static String getColumnName(int n)

    {

        // initialize output string as empty

        StringBuilder result = new StringBuilder();

        while (n > 0)

        {

            // find the index of the next letter and concatenate the letter

            // to the solution

            // here index 0 corresponds to ‘A’, and 25 corresponds to ‘Z’

            int index = (n 1) % 26;

            result.append((char)(index + ‘A’));

            n = (n 1) / 26;

        }

        return result.reverse().toString();

    }

    public static void main(String[] args)

    {

        // generate column names for 10 random numbers between 1–1000

        for (int i = 1; i <= 10; i++)

        {

            int r = new Random().nextInt(1000) + 1;

            System.out.println(r + » — « + getColumnName(r));

        }

    }

}

Download  Run Code

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

from random import randint

# Function to convert a given number to an Excel column

def getColumnName(n):

    # initialize output string as empty

    result = »

    while n > 0:

        # find the index of the next letter and concatenate the letter

        # to the solution

        # here index 0 corresponds to ‘A’, and 25 corresponds to ‘Z’

        index = (n 1) % 26

        result += chr(index + ord(‘A’))

        n = (n 1) // 26

    return result[::1]

if __name__ == ‘__main__’:

    # generate column names for 10 random numbers between 1–1000

    for i in range(1, 11):

        r = randint(1, 1000)

        print(r, ‘—’, getColumnName(r))

Download  Run Code

Output (will vary):

 
585 — VM
873 — AGO
269 — JI
849 — AFQ
288 — KB
962 — AJZ
549 — UC
572 — UZ
485 — RQ
704 — AAB

 
Also See:

Convert column name in Excel to the corresponding number

Thanks for reading.

Please use our online compiler to post code in comments using C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages.

Like us? Refer us to your friends and help us grow. Happy coding :)

Text to Columns is an amazing feature in Excel that deserves a  lot more credit than it usually gets.

As it’s name suggests, it is used to split the text into multiple columns. For example, if you have a first name and last name in the same cell, you can use this to quickly split these into two different cells.

This can be really helpful when you get your data from databases or you import it from other file formats such as Text or CSV.

In this tutorial, you’ll learn about many useful things that can be done using Text to Columns in Excel.

Where to Find Text to Columns in Excel

To access Text to Columns, select the dataset and go to Data → Data Tools → Text to Columns.

excel text to columns - in-ribbon

This would open the Convert Text to Columns Wizard.

This wizard has three steps and takes some user inputs before splitting the text into columns (you will see how these different options can be used in examples below).

To access Text to Columns, you can also use the keyboard shortcut – ALT + A + E.

Now let’s dive in and see some amazing stuff you can do with Text to Columns in Excel.

Example 1 – Split Names into the First Name and Last Name

Suppose you have a dataset as shown below:

excel text to columns - names-dataset

To quickly split the first name and the last name and get these in separate cells, follow the below steps:

This would instantly give you the results with the first name in one column and last name in another column.

excel text to columns - names-split

Note:

  • This technique works well when you the name constitutes of the first name and the last name only. In case there are initials or middle names, then this might not work. Click here for a detailed guide on how to tackle cases with different combinations of names.
  • The result you get from using the Text to Columns feature is static. This means that if there are any changes in the original data, you’ll have to repeat the process to get updated results.
Also read: How to Sort by the Last Name in Excel

Example 2 – Split Email Ids into Username and Domain Name

Text to Columns allows you to choose your own delimiter to split text.

This can be used to split emails addresses into usernames and domain names as these are separated by the @ sign.

Suppose you have a dataset as shown below:

excel text to columns - email-address

These are some fictional email ids of some cool superheroes (except myself, I am just a regular wasting-time-on-Netflix kinda guy).

Here are the steps to split these usernames and domain names using the Text to Columns feature.

This would split the email address and give you the first name and the last name in separate cells.

excel text to columns - email-address-split

Example 3 – Get the Root Domain from URL

If you work with web URLs, you may sometimes need to know the total number of unique root domains.

For example, in case of http://www.google.com/example1 and http://google.com/example2, the root domain is the same, which is www.google.com

Suppose you have a dataset as shown below:

excel text to columns - url

Here are the steps to get the root domain from these URLs:

This would split the URL and give you the root domain (in the third column as there were two forward slashes before it).

excel text to columns - url-split

Now if you want to find the number of unique domains, just remove the duplicates.

Note: This works well when you have all the URLs that have http:// in the beginning. If it doesn’t, then you will get the root domain in the first column itself. A good practice is to make these URLs consistent before using Text to Columns.

Example 4 – Convert Invalid Date Formats Into Valid Date Formats

If you get your data from databases such as SAP/Oracle/Capital IQ, or you import it from a text file, there is a possibility that the date format is incorrect (i.e., a format that Excel does not consider as date).

There are only a couple of formats that Excel can understand, and any other format needs to be converted into a valid format to be used in Excel.

Suppose you have dates in the below format (which are not in the valid Excel date format).

excel text to columns - invalid-date-formats

Here are the steps to convert these into valid date formats:

This would instantly convert these invalid date formats into valid date formats that you can use in Excel.

Example 5 – Convert Text to Numbers

Sometimes when you import data from databases or other file formats, the numbers are converted into text format.

There are several ways this can happen:

  • Having an apostrophe before the number. This leads to the number being treated as text.
  • Getting numbers as a result of text functions such as LEFT, RIGHT, or MID.

The problem with this is that these numbers (which are in text format) are ignored by Excel functions such as SUM and AVERAGE.

Suppose you have a dataset as shown below where the numbers are in the text format (note that these are aligned to the left).

excel text to columns - number-in-text-format

Here are the steps to use Text to Columns to convert text to numbers

This would convert these numbers back into General format that can now be used in formulas.

Example 6 – Extract First five Characters of a String

Sometimes you may need to extract the first few characters of a string. These could be the case when you have transactional data and the first five characters (or any other number of characters) represent a unique identifier.

For example, in the data set shown below, the first five characters are unique to a product line.

excel text to columns - transaction-ids

Here are the steps to quickly extract the first five characters from this data using Text to Columns:

This would split your data set and give you the first five characters of each transaction id in one column and rest all in the second column.

excel text to columns - transaction-ids-split

Note: You can set more than one vertical line as well to split the data into more than 2 columns. Just click anywhere in the Data Preview area and drag the cursor to set the divider.

Example 7 – Convert Numbers with Trailing Minus Sign to negative numbers

While this is not something that may encounter often, but sometimes, you may find yourself fixing the numbers with trailing minus signs and making these numbers negative.

Text to Columns is the perfect way to get this sorted.

Suppose you have a dataset as shown below:

excel text to columns - numbers-with-trailing-minus

Here are the steps to convert these trailing minuses into negative numbers:

This would instantly place the minus sign from the end of the number of the beginning of it. Now you can easily use these numbers in formulas and calculations.

You May Also Like the Following Excel Tutorials:

  • CONCATENATE Excel Ranges (with and without separator)
  • Excel AUTOFIT: Make Rows/Columns Fit the Text Automatically
  • How to Transpose Data in Excel.
  • How to Split Cells in Excel.
  • How to Merge Cells in Excel the Right Way.
  • How to Find Merged Cells in Excel (and get rid of it)
  • How to Remove Time from Date in Excel
  • How to Convert Text to Date in Excel

Problem #1 VLOOKUP Doesn’t Work

One of the more common reasons VLOOKUP fails to perform as expected is when the data we are searching for is interpreted as a number, but the list we are searching through has numbers stored as text.

The numbers look the same to our eyes, but Excel’s “eyes” are more discerning.  If the data types don’t coincide, Excel will fail to find a match.

Numbers are sometimes converted to text to exclude the number from certain calculations.

A common method of conversion is to preface the number with an apostrophe, also referred to as a single-quote.

Another common conversion method is to format the cell as text prior to entering the data.

Any value placed in the cell will be perceived by Excel as text.

The biggest challenge is when neither of these techniques have been used but the problem persists.

This is usually the result of a copy/paste action from some external data source.

Demonstrating the Problem

Using the list below; let’s enter a value in cell D2 to search for one of the code numbers in column A of the table.

We will then create a VLOOKUP formula to search for the value in cell D2 and return a description from the table and place it in cell D3.

=VLOOKUP(D3,A2:B11,2,False)

NOTE: If you are unfamiliar with the VLOOKUP function, see the link below this tutorial for a video detailing the operations and use of the VLOOKUP function.

Notice that the result of the VLOOKUP formula is a #N/A error message.

This is because our value in cell D2 is a number while the matching “number” in cell A4 is text.  They look the same to our eyes, but not Excel’s.

Solving the Problem

We will perform a bulk conversion of the data in column A of our table.

Step 1:  Select all the data in column A (A2 through A11)

Step 2:  Select Data (tab) -> Data Tools (group) -> Text to Columns

Step 3:  In the Convert Text to Columns Wizard, click Finish

The VLOOKUP formula now performs as expected.

The Text to Columns tool transformed all our numbers stored as text into actual numbers.

Problem #2 Dates aren’t Recognized as Dates

The below table has dates imported from SAP.

The numbers in column B appear to be dates.  Although they may not be formatted in the best way, we are still able to understand that the date in cell B4 is August 1, 2018.

A simple way to determine how Excel is interpreting the data is to access the filter dropdown list.

Notice that the data is just listed in a flat list.  The data is not being grouped by any year/month/day hierarchy.

Excel is smart when it comes to changing the filter options based on the perceived data type.  If the data looks like text, we are presented with Text Filters.  If the data looks like dates, we are presented with Date Filters, and if the data looks like numbers, we are presented with Number Filters.

Text Filters:

Date Filters:

Number Filters:

As a side test, if we attempt to extract the year from the date in cell B4, we are returned an error message.

=YEAR(B4)

If we attempt to format the dates in column B, the formatting fails.

Solving the Problem

We will use the same Text to Columns tool to solve this problem.

Step 1:  Select the dates (B4 through B19)

Step 2:  Select Data (tab) -> Data Tools (group) -> Text to Columns

We need to add an additional step for this solution.  We can’t accept all the default settings of the Text to Columns tool and have it perform as previously witnessed.

Step 3:  Click the Next button two times to advance to Step 3 of 3 in the Convert Text to Columns Wizard.

Set the Column Date Format option to Date and select the appropriate date format for the data.  In our case, we will select the YMD format.

Click Finish to be presented with your newly converted dates.

Testing the Filters

If we select the filter dropdown from the date column, we see that Excel is interpreting the data as dates and we have a year/month/day hierarchy to work with in data selection.

Additional Information

For information regarding the purpose and use of the VLOOKUP function, see the video link below.

Practice Workbook

Feel free to Download the Workbook HERE.

Excel Download Practice file

Published on: January 31, 2019

Last modified: March 2, 2023

Microsoft Most Valuable Professional

Leila Gharani

I’m a 5x Microsoft MVP with over 15 years of experience implementing and professionals on Management Information Systems of different sizes and nature.

My background is Masters in Economics, Economist, Consultant, Oracle HFM Accounting Systems Expert, SAP BW Project Manager. My passion is teaching, experimenting and sharing. I am also addicted to learning and enjoy taking online courses on a variety of topics.

Понравилась статья? Поделить с друзьями:
  • Excel convert from date to text
  • Excel convert format to value
  • Excel convert date values
  • Excel convert date to excel number
  • Excel convert columns to one row