Finding numbers within a range on a x,y grid

asunwatcher

New Member
Joined
Oct 9, 2010
Messages
24
Hi there,

I have a list of places each with a grid reference (longitude / latitude). They are not arranged in any order. I am given a starting grid reference and need to select a place at random that is within a specified distance (this is given in the units of the grid).

I see the steps as follows:

1) Randbetween (1, number of places that fall within the given area) e.g. 2

2) Return the value of the 2nd place within the area.

Any ideas?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
So I'm just working out the logic and I can't see a way around using a VDU, which, I think, would work along these lines:

1. Find out how many locations are within my required range - this can be done simply using a sumif statement

=SUMIFS(G:G,H:H,"<="&(C4+E4),I:I,"<="&(D4+E4), H:H,">="&(C4-E4),I:I,">="&(D4-E4))

Row G: a row of 1's beside each grid reference
Row H: x - grid reference
Row I: y - grid ref

C4 - starting x-ref
D4 - starting y-ref
E4 - range for x and y

2. Generate a random number using randbetween(1, number of places that match from 1. )

3. This is where I'm stuck

i = 0

While i < RandomNumber

j = 1

IF (H(j) "<="&(C4+E4)) AND (I (j) "<="& (D4+E4)) AND (H(j) ,">="&(C4-E4)) AND (I(j),">="&(D4-E4))

THEN i = i+1 and j = j + 1

ELSE j = j+1

End

How do I turn that into a VDU?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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