 # Convert integer to Excel column

Hello, I have managed to get the column number e.g. 4 and I want to change this into “D” so that I can use this to write stuff in to Excel.

Any help?

2 Likes

Hi @mzucker

What do you mean to change the 4 to D ?

cheers Happy learning 1 Like

please explain with a scenario, what you have stated here is too vague for us to understand what you are asking.

2 Likes

Sorry guys, for example, I have got the column number/index in a datatable (4). I have also got the row number e.g. 4. In VBA, I would write this as (4,4) but UiPath does not allow me to do this as I would need to write it as (D4). Therefore, is there a way to convert the integer 4 to the corresponding alphabet/Excel letter (D)

Sorry for any confusion!

2 Likes

Hi @mzucker

Actually i dont get the issue but if you want to transform the 4 to D just use simple case is fine.

cheers Happy learning 1 Like

what is simple case?

2 Likes

Hi @mzucker

cheers Happy learning 1 Like

Hello @mzucker

use this code
`Convert.ToChar(Convert.ToUInt16("@"c)+4)`

`Convert.ToChar(Convert.ToUInt16("A"c)+3)`

Use what suits you the best !!!

As @DanielMitchell said below the above could work for 26 letters.You could always get two letter by using an IF condition and assigning the above code twice with a + sign like this

`Convert.ToChar(Convert.ToUInt16("A"c)+3)`+`Convert.ToChar(Convert.ToUInt16("A"c)+3)`

So If the digits are higher then I would suggest you to use @DanielMitchell link i tried the logic and methods used in that link and it works flawlessly. Check the workflow below it contains logic used in that link
ColumnLetterFor.xaml (7.3 KB)

1 Like

The formula at the link above should help you. This will work for any number of columns, including higher than 26 where excel has “AA” and so on.

2 Likes

Hello, here is the code that converts any index to a column name ChangeColumnNoToName.xaml (11.6 KB)

2 Likes

Hi,
Converting the Excel Column type . you can use the “ChangeCellType”. Which is existing in the below link.

Regards
Balamurugan.S