Finding Column Index value in Excel

I am trying to find the location of a specific cell and applying that location as a value to the variable Location. The column I am looking for is the one with the column header of the variable State. In my example this column header is in Column AG. However, it keeps assigning the column as column A. I am not sure if there is something specific that needs to be done when dealing with columns with double letters etc.

1 Like

Fine the reason is there is no ASCII code for AG combined together we have for A and G in separate but here we are trying to get them together probably with value 100 but ascii for 100 is d
Thats the reason why it was not getting us the right cell position

so lets do one thing
–First lets get the cell position
out_cell = OhioCashBS770.Columns.IndexOf(State)
where out_cell is a int32 value
so it will be like out_cell = 32

–then another assign activity
out_cellsub = (out_cell - 26)+1
where out_cellsub is a int32 variable
so it would be like
out_cellsub = 33 - 26
out_cellsub = 7

–now final assign activity be like this
in_cellposition = Convert.ToChar(65) + Convert.ToChar(64 + out_cellsub)
where in_cellposition is a string variable
so the output will be like
in_cellposition = ‘A’ + Convert.ToChar(64 + 7)
in_cellposition = ‘A’ + ‘G’
in_cellposition = "AG"

–Now finally inthe cell range mention as
in_cellposition + Convert.ToString(OhioCashBS770.Rows.IndexOf(row)+2)

this will be now AG+somerownumber in string

hope this would help you
kindly correct me if i m wrong and let know for any queries or clarification
Cheers @RPANovice1


Cheers is right…pretty sure I would have never thought of this. Thanks for the response, I will let you know how it turns out.

It worked…you are awesome!

Cheers @RPANovice1

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.