# Find column number from cell position in a table

Known variables: Number of rows, number of columns, number of cells, cell index.

Find: column number relative to cell index.

Example:

1 2 3 4
5 6 7 8
9


What function can I use to find that 6 is in column 2 and row 2?

-
6%4=2 So, number % the number of rows – lab bhattacharjee Jan 31 '13 at 15:38
That's what I had in my code at first - not sure how I convinced myself it wasn't right. Maybe it's the lack of sleep; time for bed, thanks! – Marc05 Jan 31 '13 at 15:50
Now that I'm awake, I remember why that didn't work - 8 mod 4 = 0. So any number on the 4th row will always = 0. I guess I'll have to do some conditionals to get it working, but I was hoping for some sort of expression or something. – Marc05 Feb 1 '13 at 3:37

For the row, you can use 1+floor((cell index-1)/number of columns)

For the column, 1+(cell index-1)% number of columns

The 1+ and -1 are reason to use a base of zero-then they go away.

Generally, if you have "end effects" like your 8%4=0 they can be handled by adding or subtracting to put the break where you want it.

-