# Move to cell in predefined area based on random number.

• Thanks in advance for any insight to this problem.

What I would like to do is move from the Activecell to a cell defined by a random number. Picture a Square board game. 10 cells wide 10 cells deep. What should happen is as follows.
Lets say you start in A1 and the random number is 5. The new Active cell should now be E1. But if you start in A1 and an 11 is pulled then you should end up in J2. Then eventually working around in a complete circle back to A1 and so on.

See photo for an example. Only the red cells should be able to be selected. Although the red is just to show what i mean and will not be in the game. [ATTACH=CONFIG]49807[/ATTACH]

Thanks again.

## Images

[SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

• Re: Move to cell in predefined area based on random number.

I have not understood complete course of actions.

any how try this macro and if necessary modify it

if reverting to newsgroup explain wih examlples where the macro is wrong.

tests:
select A1 and run macro and input 5 is it ok
select A1 and run macro input 12 and see
select some other cell and run macro input some number and chceck

• Re: Move to cell in predefined area based on random number.

Thanks for the reply. I appreciate your efforts. Is it possible to predefine a named range for this and make it loop. Lets say the named range is Circle. It consists of a grid 2 x 2 cells. A1 B1 A2 B2. A1 is the start if a 1 is rolled it moves to B2. If next a 2 is rolled it moves to A2. It moved down and back over. Then lets say a 3 is rolled, it would then end up at B2. Making a complete circle and staying inside the named range.

I hope that helps clear it it a bit.

[SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

• Re: Move to cell in predefined area based on random number.

If there are no restrictions on the random number, it doesn't matter where one starts.

Code
``````With Range("A1:C4")
.Item((Rnd() * .Cells.Count) + 1).Select
End With``````
• Re: Move to cell in predefined area based on random number.

Thats close Mike,

But instead of Rnd can we incorporate my source data?

Code
``````With Range("GamePath")
.Item((Rnd() * .Cells.Count) + 1).Select
End With

Sheets("Data").Range("D4").Value   <<<< Replace Rnd?``````

[SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

## Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!