Column number to column name excel

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

Pieter van der Westhuizen

Convert an Excel column number to a column name or letter: C# and VB.NET examples

Posted on Wednesday, November 13th, 2013 at 8:46 am by .

Excel worksheet size has increased dramatically from Excel 2000 to Excel 2007. In fact, the number of rows an Excel 2013 worksheet can support has increased 16 times and the number of columns 64 times more than the number Excel 2000 could handle. Below is a table displaying the number of columns and rows the different versions of Excel can contain:

Microsoft Excel version Number of worksheet rows Number of worksheet columns
Excel 2013 1 048 576 16 384
Excel 2010 1 048 576 16 384
Excel 2007 1 048 576 16 384
Excel 2003 65 536 256
Excel 2000 65 536 256
  • Getting the column letter by column number
  • Getting the column index by column name

Getting the column letter by column index

There are a lot of examples floating around on the internet on how to convert Excel column numbers to alphabetical characters. There are a few ways to get the column letter, using either vanilla C# or VB.NET, Excel formulas or the Excel object model. Let’s take a look at some of the solutions.

Using C# or VB.NET

C# example:

static string ColumnIndexToColumnLetter(int colIndex)
{
    int div = colIndex;
    string colLetter = String.Empty;
    int mod = 0;
 
    while (div > 0)
    {
        mod = (div - 1) % 26;
        colLetter = (char)(65 + mod) + colLetter;
        div = (int)((div - mod) / 26);
    }
    return colLetter;
}

C# usage:

string columnLetter = ColumnIndexToColumnLetter(100); // returns CV

VB.NET example:

Private Function ColumnIndexToColumnLetter(colIndex As Integer) As String
    Dim div As Integer = colIndex
    Dim colLetter As String = String.Empty
    Dim modnum As Integer = 0
 
    While div > 0
        modnum = (div - 1) Mod 26
        colLetter = Chr(65 + modnum) & colLetter
        div = CInt((div - modnum)  26)
    End While
 
    Return colLetter
End Function

VB.NET usage:

Dim columnLetter As String = ColumnIndexToColumnLetter(85) ' returns CG

Using an Excel formula to convert a column number to column letter

Of course, if you’re in Excel and need to get the column letter based on a number, you can always use the ADDRESS function. The function is pretty straight forward; it requires a row and column number, and in our case, we need to specify the abs_num parameter, which can be one of four possible options:

abs_num Returns
1 or omitted Absolute
2 Absolute row and relative column
3 Relative row and absolute column
4 Relative

Consider the following formula:
=ADDRESS(1,5,1)

By changing the abs_num parameter, you’ll see the following result:

abs_num Formula Result Description
1 or omitted =ADDRESS(1,5,1) $E$1 Absolute
2 =ADDRESS(1,5,2) E$1 Absolute row and relative column
3 =ADDRESS(1,5,3) $E1 Relative row and absolute column
4 =ADDRESS(1,5,4) E1 Relative

Notice that in all the four cases, we get the column letter, in this case E, back as well as the row number. By setting the abs_num parameter to 4 and replacing the row number, we can effectively return the column letter using the following formula:

=SUBSTITUTE(ADDRESS(1,5,4),”1″,””)

Using the Excel Object Model to convert column numbers to alphabetic format

Of course, you could always use the Excel object model to get the column letter. Much like the ADDRESS function, you use the Address property of the Range object to determine the address of the column and then simply replace the row number as illustrated below:

C# example:

private void columnLetterRibbonButton_OnClick(object sender,
    IRibbonControl control, bool pressed)
{
    Worksheet sheet = null;
    Range range = null;
    string colLetter = string.Empty;
 
    try
    {
        sheet = (Worksheet)ExcelApp.ActiveSheet;
        range = sheet.Cells[1, 50] as Excel.Range;
        colLetter = range.Address[false, false, XlReferenceStyle.xlA1];
        colLetter = colLetter.Replace("1", "");
        MessageBox.Show(String.Format(
            "Column letter for column number 50 is : {0}", colLetter));
    }
    finally
    {
        if (sheet != null) Marshal.ReleaseComObject(sheet);
        if (range != null) Marshal.ReleaseComObject(range);
    }

VB.NET example:

Private Sub GetColumnLetterRibbonButton_OnClick(sender As Object, _
    control As IRibbonControl, pressed As Boolean) Handles _
    GetColumnLetterRibbonButton.OnClick
 
    Dim sheet As Excel.Worksheet = Nothing
    Dim range As Excel.Range = Nothing
    Dim colLetter As String = String.Empty
 
    Try
        sheet = DirectCast(ExcelApp.ActiveSheet, Excel.Worksheet)
        range = TryCast(sheet.Cells(1, 50), Excel.Range)
        colLetter = range.Address(False, False, Excel.XlReferenceStyle.xlA1)
        colLetter = colLetter.Replace("1", "")
        MessageBox.Show(String.Format( _
            "Column letter for column number 50 is : {0}", colLetter))
    Finally
        If sheet IsNot Nothing Then
            Marshal.ReleaseComObject(sheet)
        End If
        If range IsNot Nothing Then
            Marshal.ReleaseComObject(range)
        End If
    End Try
End Sub

Getting the column index by column letter

What should you do in order to reverse the scenario? How do you get the Excel column letter when all you have is the column index? Let’s take a look at how you can accomplish this using C#, VB.NET, an Excel formula and the Excel object model.

Using C# or VB.NET

C# example:

public static int ColumnLetterToColumnIndex(string columnLetter)
{
    columnLetter = columnLetter.ToUpper();
    int sum = 0;
 
    for (int i = 0; i < columnLetter.Length; i++)
    {
        sum *= 26;    
        sum += (columnLetter[i] - 'A' + 1);
    }
    return sum;
}

C# usage:

int columnIndex = ColumnLetterToColumnIndex("XFD"); // returns 16384

VB.NET example:

Public Function ColumnLetterToColumnIndex(columnLetter As String) As Integer
    columnLetter = columnLetter.ToUpper()
    Dim sum As Integer = 0
 
    For i As Integer = 0 To columnLetter.Length - 1
        sum *= 26
        Dim charA As Integer = Char.GetNumericValue("A")
        Dim charColLetter As Integer = Char.GetNumericValue(columnLetter(i))
        sum += (charColLetter - charA) + 1
    Next
    Return sum
End Function

VB.NET usage:

Dim columnIndex As Integer = ColumnLetterToColumnIndex("ADX") ' returns 703

Using an Excel formula to get the column number

Getting the column index directly in Excel is very easy. Excel has a built-in COLUMN() function. This function accepts a column reference, which is the column address. One catch though, is you have to combine the row number with the column address in order for it to work, e.g.:
=COLUMN(ADX1)

Using the Excel Object Model to convert a column letter to column number

Getting the column index is easily accomplished using the Excel object model. You first need to get a reference to a range object and then get the column number via the Column property of the Range object.

C# example:

private void getColumnIndexRibbonButton_OnClick(object sender,
    IRibbonControl control, bool pressed)
{
    Worksheet sheet = null;
    Range range = null;
    int colIndex = 0;
 
    try
    {
        sheet = (Worksheet)ExcelApp.ActiveSheet;
        range = sheet.Range["ADX1"] as Excel.Range;
        colIndex = range.Column;
        MessageBox.Show(String.Format(
            "Column index for column letter ADX is : {0}", colIndex));
    }
    finally
    {
        if (sheet != null) Marshal.ReleaseComObject(sheet);
        if (range != null) Marshal.ReleaseComObject(range);
    }
}

VB.NET example:

Private Sub GetColumnIndexRibbonButton_OnClick(sender As Object, _
    control As IRibbonControl, pressed As Boolean) Handles _
    GetColumnIndexRibbonButton.OnClick
 
    Dim sheet As Excel.Worksheet = Nothing
    Dim range As Excel.Range = Nothing
    Dim colIndex As Integer = 0
 
    Try
        sheet = DirectCast(ExcelApp.ActiveSheet, Excel.Worksheet)
        range = TryCast(sheet.Range("ADX1"), Excel.Range)
        colIndex = range.Column
        MessageBox.Show([String].Format( _
            "Column index for column letter ADX is : {0}", colIndex))
    Finally
        If sheet IsNot Nothing Then
            Marshal.ReleaseComObject(sheet)
        End If
        If range IsNot Nothing Then
            Marshal.ReleaseComObject(range)
        End If
    End Try
End Sub

Thank you for reading. Until next time, keep coding!

Available downloads:

This sample Excel add-in was developed using Add-in Express for Office and .net:

Sample add-ins and applications (C# and VB.NET)

You may also be interested in:

  • Creating COM add-ins for Excel 2013 – 2007. Customizing Excel Ribbon
  • Excel add-in development in Visual Studio

Содержание

  1. Convert an Excel column number to a column name or letter: C# and VB.NET examples
  2. Getting the column letter by column index
  3. Using C# or VB.NET
  4. Using an Excel formula to convert a column number to column letter
  5. Using the Excel Object Model to convert column numbers to alphabetic format
  6. Getting the column index by column letter
  7. Using C# or VB.NET
  8. Using an Excel formula to get the column number
  9. Using the Excel Object Model to convert a column letter to column number
  10. Available downloads:
  11. MS Excel 2016: How to Change Column Headings from Numbers to Letters
  12. Convert spreadsheet number to column letter
  13. 17 Answers 17
  14. Linked
  15. Related
  16. Hot Network Questions
  17. Subscribe to RSS
  18. Find Excel column name from a given column number
  19. Python
  20. Javascript
  21. How to convert Excel column numbers into alphabetical characters
  22. Introduction
  23. More Information

Convert an Excel column number to a column name or letter: C# and VB.NET examples

Excel worksheet size has increased dramatically from Excel 2000 to Excel 2007. In fact, the number of rows an Excel 2013 worksheet can support has increased 16 times and the number of columns 64 times more than the number Excel 2000 could handle. Below is a table displaying the number of columns and rows the different versions of Excel can contain:

Microsoft Excel version Number of worksheet rows Number of worksheet columns
Excel 2013 1 048 576 16 384
Excel 2010 1 048 576 16 384
Excel 2007 1 048 576 16 384
Excel 2003 65 536 256
Excel 2000 65 536 256
  • Getting the column letter by column number
  • Getting the column index by column name

Getting the column letter by column index

There are a lot of examples floating around on the internet on how to convert Excel column numbers to alphabetical characters. There are a few ways to get the column letter, using either vanilla C# or VB.NET, Excel formulas or the Excel object model. Let’s take a look at some of the solutions.

Using C# or VB.NET

Using an Excel formula to convert a column number to column letter

Of course, if you’re in Excel and need to get the column letter based on a number, you can always use the ADDRESS function. The function is pretty straight forward; it requires a row and column number, and in our case, we need to specify the abs_num parameter, which can be one of four possible options:

abs_num Returns
1 or omitted Absolute
2 Absolute row and relative column
3 Relative row and absolute column
4 Relative

Consider the following formula:
=ADDRESS(1,5,1)

By changing the abs_num parameter, you’ll see the following result:

abs_num Formula Result Description
1 or omitted =ADDRESS(1,5,1) $E$1 Absolute
2 =ADDRESS(1,5,2) E$1 Absolute row and relative column
3 =ADDRESS(1,5,3) $E1 Relative row and absolute column
4 =ADDRESS(1,5,4) E1 Relative

Notice that in all the four cases, we get the column letter, in this case E, back as well as the row number. By setting the abs_num parameter to 4 and replacing the row number, we can effectively return the column letter using the following formula:

Using the Excel Object Model to convert column numbers to alphabetic format

Of course, you could always use the Excel object model to get the column letter. Much like the ADDRESS function, you use the Address property of the Range object to determine the address of the column and then simply replace the row number as illustrated below:

Getting the column index by column letter

What should you do in order to reverse the scenario? How do you get the Excel column letter when all you have is the column index? Let’s take a look at how you can accomplish this using C#, VB.NET, an Excel formula and the Excel object model.

Using C# or VB.NET

Using an Excel formula to get the column number

Getting the column index directly in Excel is very easy. Excel has a built-in COLUMN() function. This function accepts a column reference, which is the column address. One catch though, is you have to combine the row number with the column address in order for it to work, e.g.:
=COLUMN(ADX1)

Using the Excel Object Model to convert a column letter to column number

Getting the column index is easily accomplished using the Excel object model. You first need to get a reference to a range object and then get the column number via the Column property of the Range object.

Thank you for reading. Until next time, keep coding!

Available downloads:

This sample Excel add-in was developed using Add-in Express for Office and .net:

Источник

MS Excel 2016: How to Change Column Headings from Numbers to Letters

This Excel tutorial explains how to change column headings from numbers (1, 2, 3, 4) back to letters (A, B, C, D) in Excel 2016 (with screenshots and step-by-step instructions).

See solution in other versions of Excel :

Question: In Microsoft Excel 2016, my Excel spreadsheet has numbers for both rows and columns. How do I change the column headings back to letters such as A, B, C, D?

Answer: Traditionally, column headings are represented by letters such as A, B, C, D. If your spreadsheet shows the columns as numbers, you can change the headings back to letters with a few easy steps.

In the example below, the column headings are numbered 1, 2, 3, 4 instead of the traditional A, B, C, D values that you normally see in Excel. When the column headings are numeric values, R1C1 reference style is being displayed in the spreadsheet.

To change the column headings to letters, select the File tab in the toolbar at the top of the screen and then click on Options at the bottom of the menu.

When the Excel Options window appears, click on the Formulas option on the left. Then uncheck the option called «R1C1 reference style» and click on the OK button.

Now when you return to your spreadsheet, the column headings should be letters (A, B, C, D) instead of numbers (1, 2, 3, 4).

Источник

Convert spreadsheet number to column letter

17 Answers 17

The xlsxwriter library includes a conversion function, xlsxwriter.utility.xl_col_to_name(index) and is on github

here is a working example:

Notice that it’s using zero-indexing.

The openpyxl library includes the conversion function (amongst others) which you are looking for, get_column_letter :

My recipe for this was inspired by another answer on arbitrary base conversion (https://stackoverflow.com/a/24763277/3163607)

Just for people still interest in this. The chosen answer by @Marius gives wrong outputs in some cases, as commented by @jspurim. Here is the my answer.

Edited after some tough love from Meta

The procedure for this involves dividing the number by 26 until you’ve reached a number less than 26, taking the remainder each time and adding 65, since 65 is where ‘A’ is in the ASCII table. Read up on ASCII if that doesn’t make sense to you.

Note that like the originally linked question, this is 1-based rather than zero-based, so A -> 1 , B -> 2 .

Recursive one line solution w/o libraries

Recursive Implementation

Iterative Implementations

Version 1: uses chr , ord

Version 2: Uses string.ascii_uppercase

Version 3: Uses divmod , chr , ord

Output: A AA AX CV IZ JJ

This simple Python function works for columns with 1 or 2 letters.

Here is a recursive solution:

The inverse can also be defined recursively, in a similar way:

Just to complicate everything a little bit I added caching, so the name of the same column will be calculated only once. The solution is based on a recipe by @Alex Benfica

an easy to understand solution:

part of the output:

Here is a modified version of the accepted answer that won’t break after ZZ .

  • It uses a single while loop and the divmod() function to simplify the calculations.
  • start_index can be 0 or 1.
  • The divmod() function returns both the quotient and the remainder when dividing two numbers, which in this case are column_int — start_index and 26.
  • The remainder is used to generate the next character for the column name, and the quotient is used as the new column_int for the next iteration.
  • The loop continues until column_int becomes zero.

Linked

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.20.43331

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Find Excel column name from a given column number

MS Excel columns have a pattern like A, B, C, …, Z, AA, AB, AC, …., AZ, BA, BB, … ZZ, AAA, AAB ….. etc. In other words, column 1 is named “A”, column 2 as “B”, and column 27 as “AA”.
Given a column number, find its corresponding Excel column name. The following are more examples.

Thanks to Mrigank Dembla for suggesting the below solution in a comment.
Suppose we have a number n, let’s say 28. so corresponding to it we need to print the column name. We need to take the remainder with 26.

If the remainder with 26 comes out to be 0 (meaning 26, 52, and so on) then we put ‘Z’ in the output string and new n becomes n/26 -1 because here we are considering 26 to be ‘Z’ while in actuality it’s 25th with respect to ‘A’.

Similarly, if the remainder comes out to be non-zero. (like 1, 2, 3, and so on) then we need to just insert the char accordingly in the string and do n = n/26.

Finally, we reverse the string and print.

Example:
n = 700
The remainder (n%26) is 24. So we put ‘X’ in the output string and n becomes n/26 which is 26.
Remainder (26%26) is 0. So we put ‘Z’ in the output string and n becomes n/26 -1 which is 0.

Following is the implementation of the above approach.

Python

Javascript

Time Complexity: O(log26n), as we are using a loop and in each traversal, we decrement by floor division of 26.

Auxiliary Space: O(50), as we are using extra space for storing the result.
Method 2
The problem is similar to converting a decimal number to its binary representation but instead of a binary base system where we have two digits only 0 and 1, here we have 26 characters from A-Z.
So, we are dealing with base 26 instead of base binary.
That’s not where the fun ends, we don’t have zero in this number system, as A represents 1, B represents 2 and so on Z represents 26.
To make the problem easily understandable, we approach the problem in two steps:

  1. Convert the number to base 26 representation, considering we have 0 also in the system.
  2. Change the representation to the one without having 0 in its system.

HOW? Here is an example

Step 1:
Consider we have number 676, How to get its representation in the base 26 system? In the same way, we do for a binary system, Instead of division and remainder by 2, we do division and remainder by 26.

Step2
But Hey, we can’t have zero in our representation. Right? Because it’s not part of our number system. How do we get rid of zero? Well it’s simple, but before doing that let’s remind one simple math trick:

  • In a decimal number system to deal with zero, we borrow 10 and subtract 1 from the next significant.
  • In the Base 26 Number System to deal with zero, we borrow 26 and subtract 1 from the next significant bit.

So Convert 10026 to a number system that does not have ‘0’, we get (25 26)26
Symbolic representation of the same is: YZ

Источник

How to convert Excel column numbers into alphabetical characters

Introduction

This article discusses how to use the Microsoft Visual Basic for Applications (VBA) function in Microsoft Excel to convert column numbers into their corresponding alphabetical character designator for the same column.

For example, the column number 30 is converted into the equivalent alphabetical characters «AD».

More Information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

The ConvertToLetter function works by using the following algorithm:

  1. Let iCol be the column number. Stop if iCol is less than 1.
  2. Calculate the quotient and remainder on division of (iCol — 1) by 26, and store in variables a and b .
  3. Convert the integer value of b into the corresponding alphabetical character (0 => A, 25 => Z) and tack it on at the front of the result string.
  4. Set iCol to the divisor a and loop.

For example: The column number is 30.

(Loop 1, step 1) The column number is at least 1, proceed.

(Loop 1, step 2) The column number less one is divided by 26:

29 / 26 = 1 remainder 3. a = 1, b = 3

(Loop 1, step 3) Tack on the (b+1) letter of the alphabet:

3 + 1 = 4, fourth letter is «D». Result = «D»

(Loop 1, step 4) Go back to step 1 with iCol = a

(Loop 2, step 1) The column number is at least 1, proceed.

(Loop 2, step 2) The column number less one is divided by 26:

0 / 26 = 0 remainder 0. a = 0, b = 0

(Loop 2, step 3) Tack on the b+1 letter of the alphabet:

0 + 1 = 1, first letter is «A» Result = «AD»

(Loop 2, step 4) Go back to step 1 with iCol = a

(Loop 3, step 1) The column number is less than 1, stop.

The following VBA function is just one way to convert column number values into their equivalent alphabetical characters:

Note This function only converts integers that are passed to it into their equivalent alphanumeric text character. It does not change the appearance of the column or the row headings on the physical worksheet.

Источник

MS Excel columns have a pattern like A, B, C, …, Z, AA, AB, AC, …., AZ, BA, BB, … ZZ, AAA, AAB ….. etc. In other words, column 1 is named “A”, column 2 as “B”, and column 27 as “AA”.
Given a column number, find its corresponding Excel column name. The following are more examples.

Input          Output
 26             Z
 51             AY
 52             AZ
 80             CB
 676            YZ
 702            ZZ
 705            AAC

Thanks to Mrigank Dembla for suggesting the below solution in a comment.
Suppose we have a number n, let’s say 28. so corresponding to it we need to print the column name. We need to take the remainder with 26. 

If the remainder with 26 comes out to be 0 (meaning 26, 52, and so on) then we put ‘Z’ in the output string and new n becomes n/26 -1 because here we are considering 26 to be ‘Z’ while in actuality it’s 25th with respect to ‘A’.

Similarly, if the remainder comes out to be non-zero. (like 1, 2, 3, and so on) then we need to just insert the char accordingly in the string and do n = n/26.

Finally, we reverse the string and print. 

Example: 
n = 700
The remainder (n%26) is 24. So we put ‘X’ in the output string and n becomes n/26 which is 26. 
Remainder (26%26) is 0. So we put ‘Z’ in the output string and n becomes n/26 -1 which is 0.

Following is the implementation of the above approach.

C++

#include <bits/stdc++.h>

#define MAX 50

using namespace std;

void printString(int n)

{

    char str[MAX];

    int i = 0;

    while (n > 0) {

        int rem = n % 26;

        if (rem == 0) {

            str[i++] = 'Z';

            n = (n / 26) - 1;

        }

        else

        {

            str[i++] = (rem - 1) + 'A';

            n = n / 26;

        }

    }

    str[i] = '';

    reverse(str, str + strlen(str));

    cout << str << endl;

    return;

}

int main()

{

    printString(26);

    printString(51);

    printString(52);

    printString(80);

    printString(676);

    printString(702);

    printString(705);

    return 0;

}

Java

public class ExcelColumnTitle {

    private static void printString(int columnNumber)

    {

        StringBuilder columnName = new StringBuilder();

        while (columnNumber > 0) {

            int rem = columnNumber % 26;

            if (rem == 0) {

                columnName.append("Z");

                columnNumber = (columnNumber / 26) - 1;

            }

            else

            {

                columnName.append((char)((rem - 1) + 'A'));

                columnNumber = columnNumber / 26;

            }

        }

        System.out.println(columnName.reverse());

    }

    public static void main(String[] args)

    {

        printString(26);

        printString(51);

        printString(52);

        printString(80);

        printString(676);

        printString(702);

        printString(705);

    }

}

Python

MAX = 50

def printString(n):

    string = [""] * MAX

    i = 0

    while n > 0:

        rem = n % 26

        if rem == 0:

            string[i] = 'Z'

            i += 1

            n = (n / 26) - 1

        else:

            string[i] = chr((rem - 1) + ord('A'))

            i += 1

            n = n / 26

    string[i] = ''

    string = string[::-1]

    print "".join(string)

printString(26)

printString(51)

printString(52)

printString(80)

printString(676)

printString(702)

printString(705)

C#

using System;

class GFG{

static String reverse(String input)

{

    char[] reversedString = input.ToCharArray();

    Array.Reverse(reversedString);

    return new String(reversedString);

}

private static void printString(int columnNumber)

{

    String columnName = "";

    while (columnNumber > 0)

    {

        int rem = columnNumber % 26;

        if (rem == 0)

        {

            columnName += "Z";

            columnNumber = (columnNumber / 26) - 1;

        }

        else

        {

            columnName += (char)((rem - 1) + 'A');

            columnNumber = columnNumber / 26;

        }

    }

    columnName = reverse(columnName);

    Console.WriteLine(columnName.ToString());

}

public static void Main(String[] args)

{

    printString(26);

    printString(51);

    printString(52);

    printString(80);

    printString(676);

    printString(702);

    printString(705);

}

}

Javascript

<script>

function printString(columnNumber)

{

        let columnName = [];

        while (columnNumber > 0) {

            let rem = columnNumber % 26;

            if (rem == 0) {

                columnName.push("Z");

                columnNumber = Math.floor(columnNumber / 26) - 1;

            }

            else

            {

                columnName.push(String.fromCharCode((rem - 1) + 'A'.charCodeAt(0)));

                columnNumber = Math.floor(columnNumber / 26);

            }

        }

        document.write(columnName.reverse().join("")+"<br>");

}

printString(26);

printString(51);

printString(52);

printString(80);

printString(676);

printString(702);

printString(705);

</script>

Output

Z
AY
AZ
CB
YZ
ZZ
AAC

Time Complexity: O(log26n), as we are using a loop and in each traversal, we decrement by floor division of 26.

Auxiliary Space: O(50), as we are using extra space for storing the result.
Method 2 
The problem is similar to converting a decimal number to its binary representation but instead of a binary base system where we have two digits only 0 and 1, here we have 26 characters from A-Z.
So, we are dealing with base 26 instead of base binary. 
That’s not where the fun ends, we don’t have zero in this number system, as A represents 1, B represents 2 and so on Z represents 26. 
To make the problem easily understandable, we approach the problem in two steps:

  1. Convert the number to base 26 representation, considering we have 0 also in the system.
  2. Change the representation to the one without having 0 in its system.

HOW? Here is an example

Step 1: 
Consider we have number 676, How to get its representation in the base 26 system? In the same way, we do for a binary system, Instead of division and remainder by 2, we do division and remainder by 26.

Base 26 representation of 676 is : 100 

Step2
But Hey, we can’t have zero in our representation. Right? Because it’s not part of our number system. How do we get rid of zero? Well it’s simple, but before doing that let’s remind one simple math trick:

Subtraction: 
5000 - 9, How do you subtract 9 from 0 ? You borrow
from next significant bit, right.  
  • In a decimal number system to deal with zero, we borrow 10 and subtract 1 from the next significant.
  • In the Base 26 Number System to deal with zero, we borrow 26 and subtract 1 from the next significant bit.

So Convert 10026 to a number system that does not have ‘0’, we get (25 26)26 
Symbolic representation of the same is: YZ 

Here is the implementation of the same:

C++

#include <iostream>

using namespace std;

void printString(int n)

{

    int arr[10000];

    int i = 0;

    while (n) {

        arr[i] = n % 26;

        n = n / 26;

        i++;

    }

    for (int j = 0; j < i - 1; j++) {

        if (arr[j] <= 0) {

            arr[j] += 26;

            arr[j + 1] = arr[j + 1] - 1;

        }

    }

    for (int j = i; j >= 0; j--) {

        if (arr[j] > 0)

            cout << char('A' + arr[j] - 1);

    }

    cout << endl;

}

int main()

{

    printString(26);

    printString(51);

    printString(52);

    printString(80);

    printString(676);

    printString(702);

    printString(705);

    return 0;

}

Java

import java.util.*;

class GFG{

static void printString(int n)

{

    int []arr = new int[10000];

    int i = 0;

    while (n > 0)

    {

        arr[i] = n % 26;

        n = n / 26;

        i++;

    }

    for(int j = 0; j < i - 1; j++)

    {

        if (arr[j] <= 0)

        {

            arr[j] += 26;

            arr[j + 1] = arr[j + 1] - 1;

        }

    }

    for(int j = i; j >= 0; j--)

    {

        if (arr[j] > 0)

            System.out.print(

                (char)('A' + arr[j] - 1));

    }

    System.out.println();

}

public static void main(String[] args)

{

    printString(26);

    printString(51);

    printString(52);

    printString(80);

    printString(676);

    printString(702);

    printString(705);

}

}

Python3

def printString(n):

    arr = [0] * 10000

    i = 0

    while (n > 0):

        arr[i] = n % 26

        n = int(n // 26)

        i += 1

    for j in range(0, i - 1):

        if (arr[j] <= 0):

            arr[j] += 26

            arr[j + 1] = arr[j + 1] - 1

    for j in range(i, -1, -1):

        if (arr[j] > 0):

            print(chr(ord('A') +

                  (arr[j] - 1)), end = "");

    print();

if __name__ == '__main__':

    printString(26);

    printString(51);

    printString(52);

    printString(80);

    printString(676);

    printString(702);

    printString(705);

C#

using System;

class GFG{

static void printString(int n)

{

  int []arr = new int[10000];

  int i = 0;

  while (n > 0)

  {

    arr[i] = n % 26;

    n = n / 26;

    i++;

  }

  for(int j = 0; j < i - 1; j++)

  {

    if (arr[j] <= 0)

    {

      arr[j] += 26;

      arr[j + 1] = arr[j + 1] - 1;

    }

  }

  for(int j = i; j >= 0; j--)

  {

    if (arr[j] > 0)

      Console.Write((char)('A' +

                     arr[j] - 1));

  }

  Console.WriteLine();

}

public static void Main(String[] args)

{

  printString(26);

  printString(51);

  printString(52);

  printString(80);

  printString(676);

  printString(702);

  printString(705);

}

}

Javascript

<script>

function printString(n){

    let arr = [];

    let i = 0;

    while (n) {

        arr[i] = n % 26;

        n = Math.floor(n / 26);

        i++;

    }

    for (let j = 0; j < i - 1; j++) {

        if (arr[j] <= 0) {

            arr[j] += 26;

            arr[j + 1] = arr[j + 1] - 1;

        }

    }

    let ans = '';

    for (let j = i; j >= 0; j--) {

        if (arr[j] > 0)

            ans += String.fromCharCode(65 + arr[j] - 1);

    }

    document.write(ans + "<br>");

}

printString(26);

printString(51);

printString(52);

printString(80);

printString(676);

printString(702);

printString(705);

</script>

Output

Z
AY
AZ
CB
YZ
ZZ
AAC

Time Complexity: O(log26n), as we are using a loop and in each traversal, we decrement by floor division of 26.

Auxiliary Space: O(10000), as we are using extra space for the array.

Method 3:

We can use a recursive function which definitely reduces the time and  increase the efficiency:

Alphabets are in sequential order like: ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’. You have experienced while using excel when you see columns and rows numbering are done in  Alphabetical ways.

Here’s How I purposefully think about the logic of how it is arranged.

(In Mathematical  terms, [a , b ] means from ‘a’ to ‘b’).

[1,26] = [A,Z] (Understand by ‘1’ stands for ‘A’ and ’26” stands for “Z”). For [27,52] ,it will be like [AA,AZ], For [57,78] it will be [BA,BZ]

Logic is to append an Alphabet sequentially whenever it ends up numbering at 26.

For example, if the number is ’27’ which is greater than  ’26’, then we simply need to divide by 26, and we get the remainder as 1, We see “1” as “A” and can be recursively done.

we will be using python for this.

Algorithm is:

1. Take an array and Sort the letters from A to Z . (You can also use the import string and string function to get “A to Z” in uppercase.)

2. If the number is less than or equal to ’26’, simply get the letter from the array and print it.

3. If it is greater than 26, use the Quotient  Remainder rule, if the remainder is zero, there are 2 possible ways, if the quotient is “1”, simply hash out the letter from the index [r-1]( ‘r’ is remainder), else call out the function from the num =(q-1) and append at the front to the letter indexing [r-1].

4. If the remainder is not equal to “0”, call the function for the num = (q) and append at the front to the letter indexing [r-1].

The code concerned with this is:

C++

#include<bits/stdc++.h>

using namespace std;

string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string num_hash(int num){

    if(num < 26){

      string res = "";

      res += alpha[num-1];

      return res;

    }

    else{

      int q = (num / 26);

      int r = num % 26;

      string res = "";

      if(r == 0){

        if(q == 1){

          res.append(1,alpha[(26 + r-1)%26]);

        }

        else{

          res = num_hash(q-1);

          res.append(1,alpha[(26 + r-1)%26]);

        }

      }

      else{

        res = num_hash(q);

        res.append(1,alpha[(26 + r-1)%26]);

      }

      return res;

    }

}

int main () {

    cout<< num_hash(26) << endl;

    cout<< num_hash(51) << endl;

    cout<< num_hash(52) << endl;

    cout<< num_hash(80) << endl;

    cout<< num_hash(676) << endl;

    cout<< num_hash(702) << endl;

    cout<< num_hash(705) << endl;

    return 0;

}

Java

import java.io.*;

class GFG

{

  static String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  static String num_hash(int num){

    if(num < 26)

      return Character.toString(alpha.charAt(num-1));

    else{

      int q = Math.floorDiv(num, 26);

      int r = num % 26;

      if(r == 0){

        if(q == 1){

          return Character.toString(alpha.charAt((26 + r-1)%26));

        }

        else

          return num_hash(q-1) + alpha.charAt((26 + r-1)%26);

      }

      else

        return num_hash(q) + alpha.charAt((26 + r-1)%26);

    }

  }

  public static void main (String[] args) {

    System.out.println(num_hash(26));

    System.out.println(num_hash(51));

    System.out.println(num_hash(52));

    System.out.println(num_hash(80));

    System.out.println(num_hash(676));

    System.out.println(num_hash(702));

    System.out.println(num_hash(705));

  }

}

Python3

alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def num_hash(num):

    if num < 26:

        return alpha[num-1]

    else:

        q, r = num//26, num % 26

        if r == 0:

            if q == 1:

                return alpha[r-1]

            else:

                return num_hash(q-1) + alpha[r-1]

        else:

            return num_hash(q) + alpha[r-1]

print(num_hash(26))

print(num_hash(51))

print(num_hash(52))

print(num_hash(80))

print(num_hash(676))

print(num_hash(702))

print(num_hash(705))

C#

using System;

class GFG

{

static string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

static string num_hash(int num){

    if(num < 26)

    return Char.ToString(alpha[num-1]);

    else{

    int q = num/26;

    int r = num % 26;

    if(r == 0){

        if(q == 1){

        return Char.ToString(alpha[(26 + r-1)%26]);

        }

        else

        return num_hash(q-1) + alpha[(26 + r-1)%26];

    }

    else

        return num_hash(q) + alpha[(26 + r-1)%26];

    }

}

public static void Main(String[] args) {

    Console.WriteLine(num_hash(26));

    Console.WriteLine(num_hash(51));

    Console.WriteLine(num_hash(52));

    Console.WriteLine(num_hash(80));

    Console.WriteLine(num_hash(676));

    Console.WriteLine(num_hash(702));

    Console.WriteLine(num_hash(705));

}

}

Javascript

<script>

let alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

function num_hash(num)

{

    if(num < 26)

        return alpha[num-1]

    else{

        let q = Math.floor(num/26),r = num % 26

        if(r == 0){

            if(q == 1)

                return alpha[(26 + r-1)]

            else

                return num_hash(q-1) + alpha[(26 + r-1)]

        }

        else

            return num_hash(q) + alpha[r-1]

    }

}

document.write(num_hash(26),"</br>")

document.write(num_hash(51),"</br>")

document.write(num_hash(52),"</br>")

document.write(num_hash(80),"</br>")

document.write(num_hash(676),"</br>")

document.write(num_hash(702),"</br>")

document.write(num_hash(705),"</br>")

</script>

Output

Z
AY
AZ
CB
YZ
ZZ
AAC

Time Complexity: O(log26n), as we are using recursion and in each recursive call, we decrement by floor division of 26.

Auxiliary Space: O(1), as we are not using any extra space.
Related Article : 
Find the Excel column number from the column title
This article is contributed by Kartik. Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above.

Skip to content

Column Number to Column Name

  • Column Number to Column Name

Excel VBA Column Number to Name example macro will convert column number to Excel alphabetic Letter character column name. Most of the time while automating many tasks using Excel VBA, it may be required. Please find the following details about conversion of number to name. You can also say column number to column string. Or number to letter using Excel VBA. Please find the following different strategic functions to get column number to column name.

Column Number to Column Name

  • Column Number to Column Name: Easiest Approach by Replacing a Cell Address
    • Column Number to Column Name: Example and Output
  • Column Number to Column Name: By Referring Excel Range and Using SPLIT Function
    • Column Number to Column Name: Example and Output
  • Column Number to Column Name: Using Chr Function and Do While loop
    • Column Number to Column Name: Example and Output
  • Column Number to Column Name: Using Recursive Approach
    • Column Number to Column Name: Example and Output

Column Number to Column Name: Easiest Approach by Replacing a Cell Address

Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are referring a cell address.

'Easiest approach by Replacing a Cell address
Function fnColumnToLetter_CellAdressReplace(ByVal ColumnNumber As Integer)
    fnColumnToLetter_CellAdressReplace = Replace(Replace(Cells(1, ColumnNumber).Address, "1", ""), "$", "")
End Function

Column Number to Column Name: Example and Output

Please find the below example. It will show you how to get column name from column number using Excel VBA. In the below example ‘fnColumnToLetter_CellAdressReplace’ is a function name, which is written above. And “105” represents the row number of ‘fnColumnToLetter_CellAdressReplace’ function parameter.

Sub sbNumerToLetter_ExampleMacro()
    MsgBox "Column Name is : " & fnColumnToLetter_CellAdressReplace(105)
End Sub 

Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.

Column Number to Column Name1

Column Number to Column Name: By Referring Excel Range and Using SPLIT Function

Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are referring Excel range and ‘Split’ function.

'By refering Excel Range and using SPLIT function
Function fnColumnToLetter_Split(ByVal intColumnNumber As Integer)
    fnColumnToLetter_Split = Split(Cells(1, intColumnNumber).Address, "$")(1)
End Function

Column Number to Column Name: Example and Output

Please find the below example. It will show you how to get column name from column number using Excel VBA. In the below example ‘fnColumnToLetter_Split’ is a function name, which is written above. And “15” represents the row number of ‘fnColumnToLetter_Split’ function parameter.

Sub sbNumerToLetter_ExampleMacro1()
    MsgBox "Column Name is : " & fnColumnToLetter_Split(15)
End Sub

Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.

Column Number to Column Name2

Column Number to Column Name: Using Chr Function and Do While loop

Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are referring a ‘Chr’ function and Do While loop.

'Using chr function and Do  while loop
Function fnColumnToLetter_DoLoop(ByVal intColumnNumber As Integer) As String
    Dim bColDenom As Byte
    fnColumnToLetter_DoLoop = ""
    Do
        bColDenom = ((intColumnNumber - 1) Mod 26)
        fnColumnToLetter_DoLoop = Chr(bColDenom + 65) & fnColumnToLetter_DoLoop
        intColumnNumber = (intColumnNumber - bColDenom)  26
    Loop While intColumnNumber > 0
End Function

Column Number to Column Name: Example and Output

Please find the below example. It will show you how to get column name from column number using Excel VBA. In the below example ‘fnColumnToLetter_DoLoop’ is a function name, which is written above. And “10” represents the row number of ‘fnColumnToLetter_DoLoop’ function parameter.

Sub sbNumerToLetter_ExampleMacro2()
    MsgBox "Column Name is : " & fnColumnToLetter_DoLoop(10)
End Sub

Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.

Column Number to Column Name3

Column Number to Column Name: Using Recursive Approach

Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are using recursive approach.

'Using Recursive Approach
Function fnColumnToLetter_Rec(intColumnNumber As Integer) As String
    If intColumnNumber > 26 Then
        fnColumnToLetter_Rec = fnColumnToLetter_Rec((intColumnNumber - ((intColumnNumber - 1) Mod 26)) / 26) + Chr((intColumnNumber - 1) Mod 26 + 65)
    Else
        fnColumnToLetter_Rec = Chr(intColumnNumber + 64)
    End If
End Function

Column Number to Column Name: Example and Output

Here is the example macro procedure. It will show you how to get column name from column number using Excel VBA. In the below example “fnColumnToLetter_Rec” is a function name, which is written above. And “4” represents the row number of “fnColumnToLetter_Rec” function parameter.

Sub sbNumerToLetter_ExampleMacro3()
    MsgBox "Column Name is : " & fnColumnToLetter_Rec(4)
End Sub

Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.

Column Number to Column Name

More about Column Name to Column Number Conversion

Here is the link to more about how to convert column name to column number using VBA in Excel.

Column Name to Number Conversion

Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Excel VBA Project Management Templates
All-in-One Pack
120+ Project Management Templates
Essential Pack
50+ Project Management Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project Management Template

Ultimate Resource Management Template

Project Portfolio Management Templates

Related Posts

  • Column Number to Column Name: Easiest Approach by Replacing a Cell Address
  • Column Number to Column Name: Example and Output
  • Column Number to Column Name: By Referring Excel Range and Using SPLIT Function
  • Column Number to Column Name: Example and Output
  • Column Number to Column Name: Using Chr Function and Do While loop
  • Column Number to Column Name: Example and Output
  • Column Number to Column Name: Using Recursive Approach
  • Column Number to Column Name: Example and Output
  • More about Column Name to Column Number Conversion

VBA Reference

Effortlessly
Manage Your Projects

120+ Project Management Templates

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

120+ PM Templates Includes:

5 Comments

  1. arun sharma
    September 14, 2015 at 2:33 PM — Reply

    ‘=IF(MID(ADDRESS(3,COLUMN(),,,),3,1)=”$”,MID(ADDRESS(3,COLUMN(),,,),2,1),MID(ADDRESS(3,COLUMN(),,,),2,2))

    Hi ,

    I dont know excel much , but i tried to solve this by using simple formulas.

    hope you find this OK.

    Thanks
    Arun

  2. Alan Elston
    October 25, 2015 at 5:34 AM — Reply
  3. Dale
    March 12, 2016 at 2:16 AM — Reply

    Another alternative: Application.ConvertFormula(Formula,FromReferenceStyle,ToReferenceStyle)

    For example, Application.ConvertFormula(“C215”,xlR1C1,xlA1) returns:$HG:$HG and
    Application.ConvertFormula(“$HG:$HG”,xla1,xlr1c1) returns: C215

    Cheers, Dale

  4. mskkiddo
    July 14, 2016 at 5:47 PM — Reply

    Place the column number which you need to know the character in the cell “B1”
    And use the below formula rest of any cells
    =LEFT(REPLACE(CELL(“address”,OFFSET(A1,1,B1-1)),1,1,”),FIND(“$”,REPLACE(CELL(“address”,OFFSET(A1,1,B1-1)),1,1,”))-1)

  5. Akhtar
    January 11, 2023 at 3:54 AM — Reply

Effectively Manage Your
Projects and  Resources

With Our Professional and Premium Project Management Templates!

ANALYSISTABS.COM provides free and premium project management tools, templates and dashboards for effectively managing the projects and analyzing the data.

We’re a crew of professionals expertise in Excel VBA, Business Analysis, Project Management. We’re Sharing our map to Project success with innovative tools, templates, tutorials and tips.

Project Management
Excel VBA

Download Free Excel 2007, 2010, 2013 Add-in for Creating Innovative Dashboards, Tools for Data Mining, Analysis, Visualization. Learn VBA for MS Excel, Word, PowerPoint, Access, Outlook to develop applications for retail, insurance, banking, finance, telecom, healthcare domains.

Analysistabs Logo

Page load link

Go to Top

totn Excel


This Excel tutorial explains how to change column headings from numbers (1, 2, 3, 4) back to letters (A, B, C, D) in Excel 2016 (with screenshots and step-by-step instructions).

Question: In Microsoft Excel 2016, my Excel spreadsheet has numbers for both rows and columns. How do I change the column headings back to letters such as A, B, C, D?

Answer: Traditionally, column headings are represented by letters such as A, B, C, D. If your spreadsheet shows the columns as numbers, you can change the headings back to letters with a few easy steps.

In the example below, the column headings are numbered 1, 2, 3, 4 instead of the traditional A, B, C, D values that you normally see in Excel. When the column headings are numeric values, R1C1 reference style is being displayed in the spreadsheet.

Microsoft Excel

To change the column headings to letters, select the File tab in the toolbar at the top of the screen and then click on Options at the bottom of the menu.

Microsoft Excel

When the Excel Options window appears, click on the Formulas option on the left. Then uncheck the option called «R1C1 reference style» and click on the OK button.

Microsoft Excel

Now when you return to your spreadsheet, the column headings should be letters (A, B, C, D) instead of numbers (1, 2, 3, 4).

Microsoft Excel

  1. from random import randint.
  2. # Function to convert a given number to an Excel column.
  3. def getColumnName(n):
  4. # initialize output string as empty.
  5. result = “”
  6. while n > 0:
  7. # find the index of the next letter and concatenate the letter.
  8. # to the solution.

How do I number a column in Excel?

Show column number

  1. Click File tab > Options.
  2. In the Excel Options dialog box, select Formulas and check R1C1 reference style.
  3. Click OK.

What is the column name for 28 column in Excel sheet?

Excel Columns AA-AZ

Column Letter Column Number
AA 27
AB 28
AC 29
AD 30

What is column formula in Excel?

The COLUMN function returns the column number of the given cell reference. For example, the formula =COLUMN(D10) returns 4, because column D is the fourth column.

How do you create a list of columns in Excel?

You create a list in much the same way you create a worksheet. You enter information into a list by entering data into cells….Method

  1. In the first cell of the first row of the list, enter a column label.
  2. Move one cell to the right.
  3. Enter the second column label.
  4. Repeat steps 2 and 3 until finished.

What is column name in Excel?

In Microsoft Excel, the column headers are named A, B, C, and so on by default. Some users want to change the names of the column headers to something more meaningful. Unfortunately, Excel does not allow the header names to be changed.

How do I make a column header row value in Excel?

With a cell in your table selected, click on the “Format as Table” option in the HOME menu. When the “Format As Table” dialog comes up, select the “My table has headers” checkbox and click the OK button. Select the first row; which should be your header row.

How do you add a header to a formula in Excel?

Click in your table, select Design under Table Tools on the ribbon, and then uncheck “Header Row”. That should allow you to enter a formula in the cell above your table data.

How do I sort data in an Excel chart?

Hover over the top edge of a chart until you see sort by in the upper-left corner, then the name of a field, and then either asc or desc. Click the field name to sort on a different value. Click asc or desc to sort in the opposite direction. Chart sorted descending on the CountryRegion category value by default.

How do you reverse the order of a bar graph?

Right-click and select the option on very bottom of the pop-up menu called Format Axis. Then, on the Format Axis window, check the box for Categories in Reverse Order. That’s a jargony name with a straightforward purpose. It just re-sorts your bar chart in the opposite order of your table.

How do you reverse data in a bar graph?

Tip: In bar chart, reserve the x axis with righting click the x axis and selecting the Format Axis from context menu, then checking the Values in reverse order in the Format Axis dialog box. 3. Close the dialog, now the y axis order is reversed.

How do you mirror a graph on Excel?

On the Insert tab of the ribbon, in the Charts group, click on the Insert Bar Chart button and in the opened menu, click on the second option, which is Stacked Bar, among the 2-D Bar charts. This inserts a mirror bar chart into the worksheet. 3. Move the vertical axis labels to the left of the chart.

Why is my Excel backwards?

This happens because a setting in the Excel options menu called “Show sheet right to left” has been turned on. …

Я обнаружил ошибку в своем первом сообщении, поэтому решил сесть и сделать математику. Я обнаружил, что числовая система, используемая для идентификации столбцов Excel, не является базой 26, как другой человек. Рассмотрим следующее в базе 10. Вы также можете сделать это с буквами алфавита.

Пространство:……………………. S1, S2, S3: S1, S2, S3
……………………………… 0, 00, 000:.. A, AA, AAA < ш > ……………………………… 1, 01, 001:.. B, AB, AAB < ш > …………………………………,…,…:…..,…,… < ш > ……………………………… 9, 99, 999:.. Z, ZZ, ZZZ < ш > Всего состояний в космосе: 10, 100, 1000: 26, 676, 17576
Всего государств:…………… 1110……………. 18278

Таблицы Excel номеров в отдельных алфавитных пространствах с использованием базы 26. Вы можете видеть, что в общем случае прогрессия состояния пространства a, a ^ 2, a ^ 3,… для некоторой базы a, а общее число состояний a + a ^ 2 + a ^ 3 +….

Предположим, вы хотите найти общее число состояний A в первых N пробелах. Формула для этого равна A = (a) (a ^ N — 1)/(a-1). Это важно, потому что нам нужно найти пространство N, соответствующее нашему индексу K. Если я хочу выяснить, где K лежит в системе чисел, мне нужно заменить A на K и решить для N. Решение N = log { base a} (A (a-1)/a +1). Если я использую пример a = 10 и K = 192, я знаю, что N = 2.23804…. Это говорит мне, что K лежит в начале третьего пространства, так как он немного больше двух.

Следующий шаг — найти то, как далеко в текущем пространстве мы находимся. Чтобы найти это, вычтите из K A, сгенерированный с использованием пола N. В этом примере пол N равен двум. Итак, A = (10) (10 ^ 2 — 1)/(10-1) = 110, как и ожидалось, когда вы объединяете состояния первых двух пространств. Это нужно вычесть из K, потому что эти первые 110 состояний были бы учтены в первых двух пространствах. Это оставляет нас с 82 состояниями. Таким образом, в этой системе чисел представление 192 в базе 10 равно 082.

Код С# с базовым индексом нуля равен

    private string ExcelColumnIndexToName(int Index)
    {
        string range = string.Empty;
        if (Index < 0 ) return range;
        int a = 26;
        int x = (int)Math.Floor(Math.Log((Index) * (a - 1) / a + 1, a));
        Index -= (int)(Math.Pow(a, x) - 1) * a / (a - 1);
        for (int i = x+1; Index + i > 0; i--)
        {
            range = ((char)(65 + Index % a)).ToString() + range;
            Index /= a;
        }
        return range;
    }

//Старый пост

Решение на основе нуля в С#.

    private string ExcelColumnIndexToName(int Index)
    {
        string range = "";
        if (Index < 0 ) return range;
        for(int i=1;Index + i > 0;i=0)
        {
            range = ((char)(65 + Index % 26)).ToString() + range;
            Index /= 26;
        }
        if (range.Length > 1) range = ((char)((int)range[0] - 1)).ToString() + range.Substring(1);
        return range;
    }

My column headings are labeled with numbers instead of letters

  1. On the Excel menu, click Preferences.
  2. Under Authoring, click General .
  3. Clear the Use R1C1 reference style check box. The column headings now show A, B, and C, instead of 1, 2, 3, and so on.

Contents

  • 1 How do you change Excel to Numbers?
  • 2 How do I show column numbers in Excel?
  • 3 How do I convert text to values in Excel?
  • 4 How do I convert a column of numbers to column names in Excel?
  • 5 How do I change the number format in Excel?
  • 6 Why does Excel have numbers for columns?
  • 7 How do I show columns and row numbers in Excel?
  • 8 How do I get columns and row numbers in Excel?
  • 9 How do I get row numbers in Excel?
  • 10 How do I format numbers in Excel?
  • 11 What are the different ways in formatting numbers?
  • 12 How do I change the column title in Excel?
  • 13 How do I change rows and column names in Excel?
  • 14 How do I change Excel columns from numbers to alphabets?
  • 15 How do I get rid of column 1 headers in Excel?
  • 16 How do I change the row numbers in Excel?
  • 17 What is an Xlookup in Excel?
  • 18 Why can’t I see row numbers in Excel?
  • 19 How do I add a numbered list in Excel?
  • 20 How do I automatically number in sheets?

Change numbers with text format to number format in Excel for the…

  1. Select the cells that have the data you want to reformat.
  2. Click Number Format > Number. Tip: You can tell a number is formatted as text if it’s left-aligned in a cell.

How do I show column numbers in Excel?

Show column number

  1. Click File tab > Options.
  2. In the Excel Options dialog box, select Formulas and check R1C1 reference style.
  3. Click OK.

How do I convert text to values in Excel?

Use the Format Cells option to convert number to text in Excel

  1. Select the range with the numeric values you want to format as text.
  2. Right click on them and pick the Format Cells… option from the menu list. Tip. You can display the Format Cells…
  3. On the Format Cells window select Text under the Number tab and click OK.

How do I convert a column of numbers to column names in Excel?

To convert a column number to an Excel column letter (e.g. A, B, C, etc.) you can use a formula based on the ADDRESS and SUBSTITUTE functions. With this information, ADDRESS returns the text “A1”.

How do I change the number format in Excel?

You can use the Format Cells dialog to find the other available format codes:

  1. Press Ctrl+1 ( +1 on the Mac) to bring up the Format Cells dialog.
  2. Select the format you want from the Number tab.
  3. Select the Custom option,
  4. The format code you want is now shown in the Type box.

Why does Excel have numbers for columns?

Cause: The default cell reference style (A1), which refers to columns as letters and refers to rows as numbers, was changed. Solution: Clear the R1C1 reference style selection in Excel preferences. On the Excel menu, click Preferences.The column headings now show A, B, and C, instead of 1, 2, 3, and so on.

How do I show columns and row numbers in Excel?

On the Ribbon, click the Page Layout tab. In the Sheet Options group, under Headings, select the Print check box. , and then under Print, select the Row and column headings check box .

How do I get columns and row numbers in Excel?

It is quite easy to figure out the row number or column number if you know a cell’s address. If the cell address is NK60, it shows the row number is 60; and you can get the column with the formula of =Column(NK60). Of course you can get the row number with formula of =Row(NK60).

How do I get row numbers in Excel?

Use the ROW function to number rows

  1. In the first cell of the range that you want to number, type =ROW(A1). The ROW function returns the number of the row that you reference. For example, =ROW(A1) returns the number 1.
  2. Drag the fill handle. across the range that you want to fill.

How do I format numbers in Excel?

Formatting the Numbers in an Excel Text String

  1. Right-click any cell and select Format Cell.
  2. On the Number format tab, select the formatting you need.
  3. Select Custom from the Category list on the left of the Number Format dialog box.
  4. Copy the syntax found in the Type input box.

What are the different ways in formatting numbers?

How to change number formats. You can select standard number formats (General, Number, Currency, Accounting, Short Date, Long Date, Time, Percentage, Fraction, Scientific, Text) on the home tab of the ribbon using the Number Format menu. Note: As you enter data, Excel will sometimes change number formats automatically.

How do I change the column title in Excel?

Select a column, and then select Transform > Rename. You can also double-click the column header. Enter the new name.

How do I change rows and column names in Excel?

Rename columns and rows in a worksheet

  1. Click the row or column header you want to rename.
  2. Edit the column or row name between the last set of quotation marks. In the example above, you would overwrite the column name Gold Collection.
  3. Press Enter. The header updates.

How do I change Excel columns from numbers to alphabets?

To change the column headings to letters, select the File tab in the toolbar at the top of the screen and then click on Options at the bottom of the menu. When the Excel Options window appears, click on the Formulas option on the left. Then uncheck the option called “R1C1 reference style” and click on the OK button.

How do I get rid of column 1 headers in Excel?

Go to Table Tools > Design on the Ribbon. In the Table Style Options group, select the Header Row check box to hide or display the table headers. If you rename the header rows and then turn off the header row, the original values you input will be retained if you turn the header row back on.

How do I change the row numbers in Excel?

Here are the steps to use Fill Series to number rows in Excel:

  1. Enter 1 in cell A2.
  2. Go to the Home tab.
  3. In the Editing Group, click on the Fill drop-down.
  4. From the drop-down, select ‘Series..’.
  5. In the ‘Series’ dialog box, select ‘Columns’ in the ‘Series in’ options.
  6. Specify the Stop value.
  7. Click OK.

What is an Xlookup in Excel?

Use the XLOOKUP function to find things in a table or range by row.With XLOOKUP, you can look in one column for a search term, and return a result from the same row in another column, regardless of which side the return column is on.

Why can’t I see row numbers in Excel?

In order to show (or hide) the row and column numbers and letters go to the View ribbon. Set the check mark at “Headings”. That’s it!

How do I add a numbered list in Excel?

Click the Home tab in the Ribbon. Click the Bullets and Numbering option in the new group you created. The new group is on the far right side of the Home tab. In the Bullets and Numbering window, select the type of bulleted or numbered list you want to add to the text box and click OK.

How do I automatically number in sheets?

Use autofill to complete a series

  1. On your computer, open a spreadsheet in Google Sheets.
  2. In a column or row, enter text, numbers, or dates in at least two cells next to each other.
  3. Highlight the cells. You’ll see a small blue box in the lower right corner.
  4. Drag the blue box any number of cells down or across.

Понравилась статья? Поделить с друзьями:
  • Column notes in word
  • Column not adding excel
  • Column newspaper in word
  • Column naming in excel
  • Column names in excel are numbers