calculating the distance between cells in excel (randomize moving cells)

rosasellen12

New Member
Joined
Oct 20, 2022
Messages
9
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Suppose I want to compute the distance between a 3by4 cells in a square grid in excel. The distance between two cells is 1m.
Each grid cell is a number between 1 and 12 but randomized so every number can be anywhere.

tablesample.PNG


For instance: (example in the bottom-left side of the grid):

1___2___3___4

5___6___7___8

9__10__11__12


distance between cells 1 and 5 is 1
distance between cells 1 and 6 is 2
distance between cells 1 and 12 is 5

the grid can also be this and other randomized forms:
1___7___9___12

8___2___6___11

10__8___3___4

Is it possible to have the formula to be able to calculate all of the distance between 2 cells????


Thanks for any help in advance! :)
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
This is a bit long winded but i cant think of another way offhand.

=ABS(AGGREGATE(14,4,($B$15:$E$17=$A2)*(ROW($B$15:$E$17)),1)-AGGREGATE(14,4,($B$15:$E$17=B$1)*(ROW($B$15:$E$17)),1))+ABS(AGGREGATE(14,4,($B$15:$E$17=$A2)*(COLUMN($B$15:$E$17)),1)-AGGREGATE(14,4,($B$15:$E$17=B$1)*(COLUMN($B$15:$E$17)),1))
 
Upvote 0
Solution
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
This is a bit long winded but i cant think of another way offhand.

=ABS(AGGREGATE(14,4,($B$15:$E$17=$A2)*(ROW($B$15:$E$17)),1)-AGGREGATE(14,4,($B$15:$E$17=B$1)*(ROW($B$15:$E$17)),1))+ABS(AGGREGATE(14,4,($B$15:$E$17=$A2)*(COLUMN($B$15:$E$17)),1)-AGGREGATE(14,4,($B$15:$E$17=B$1)*(COLUMN($B$15:$E$17)),1))
wow, The formula seems to work also when the cell numbers are in random

I'm not sure how aggregate works, but I'll check it out! thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top