Select random cell from defined range

  • Thread starter Thread starter Tanya
  • Start date Start date
T

Tanya

Hi
I have 5 cells [range is I13:I17] each with a hyperlink to a wav file and I
would like to have a macro that randomly selects these cells to enable the
hyperlink.
Is this possible?
cheers
Tanya
 
See if this will help any....


Mark Ivey


Dim i As Integer
Sub test()
RandomNo 'call Julian's RandomNo procedure

'change as needed
Cells(i, 9).Offset(12).Select
End Sub


' The procedure below was from the following resource
'---------------------------------------------------------------------------------------
' Procedure : RandomNo
' DateTime : 10/27/2001
' Author : Julian S.
' Website :
http://www.angelfire.com/biz7/julian_s/julian/julians_macros.htm
' Purpose : For macros to generate random numbers,
' the code is takes this format -
' Int ((upperbound - lowerbound +1) * Rnd + lowerbound).
' Where the Upperbound is the largest number random number
' to be generated and Lowerbound is the lowest.
'---------------------------------------------------------------------------------------
'
Sub RandomNo()
Randomize
MyNumber = Int((5 - 1 + 1) * Rnd + 1)
'MsgBox ("The random number is ") & (MyNumber)
i = MyNumber 'added to work with the first procedure
End Sub
 
Sub ordinate()
v1 = 13
v2 = 17
j = Int(((v2 - v1 + 1) * Rnd) + v1)
Range("I" & j).Select
End Sub
 
Hi
I have 5 cells [range is I13:I17] each with a hyperlink to a wav file and I
would like to have a macro that randomly selects these cells to enable the
hyperlink.
Is this possible?
cheers
Tanya

This code will work and follow the hyperlink:

Sub RandomLink()

Dim rngTargetCell As Range
Dim iRandomNumber As Integer

Set rngTargetCell = Nothing

Randomize
iRandomNumber = Int(5 * Rnd + 13)
Set rngTargetCell = Range("I" & iRandomNumber)

rngTargetCell.Hyperlinks(1).Follow
End Sub
 
Thank you very much Alex,
It worked a treat.

Tanya

Alex Simmons said:
Hi
I have 5 cells [range is I13:I17] each with a hyperlink to a wav file and I
would like to have a macro that randomly selects these cells to enable the
hyperlink.
Is this possible?
cheers
Tanya

This code will work and follow the hyperlink:

Sub RandomLink()

Dim rngTargetCell As Range
Dim iRandomNumber As Integer

Set rngTargetCell = Nothing

Randomize
iRandomNumber = Int(5 * Rnd + 13)
Set rngTargetCell = Range("I" & iRandomNumber)

rngTargetCell.Hyperlinks(1).Follow
End Sub
 
Back
Top