Maki
Maki

Reputation: 637

How to count number of columns in between 2 cells

Is there a way to count columns in between? E.g. "name" is 3 columns from "height"

Defined name
Column A = "NAME"
Column B = "Gender"
Column C = "Height"

-------------------
1 | A | B | C | D |
-------------------
2 |Amy| F |151|N/A|
-------------------
3 |Bob| M |180|   | 
-------------------

Thank you in advance.

Upvotes: 1

Views: 8385

Answers (1)

davidhu
davidhu

Reputation: 10462

you can use the COLUMN method. It will return the column number of the reference.

Defined name
Column A = "NAME"
Column B = "Gender"
Column C = "Height"

-------------------
1 | A | B | C | D |
-------------------
2 |Amy| F |151|N/A|
-------------------
3 |Bob| M |180|   | 
-------------------

I'm assuming you had a typo and you meant NAME is two columns away from HEIGHT

=ABS(COLUMN(A2) - COLUMN(C2)) #=> 2

Upvotes: 2

Related Questions