--------------------------------------------------------------------------------
Hello,
I have a macro to generate random numbers and it updates when the sheet is recalcuted. Problem is it will run on wich ever sheet is active at the moment instead of its intended sheet. I added this code to it but it jumps to the sheet to run the macro when ever the sheet is recalculated. I need it to run automaticaly when the sheet is recalculated but with out jumping me to that particular worksheet.
Code:
With Worksheets("TL")
.Select
/Code
Below is the entire macro
Code:
Option Explicit
Sub TLtestgenerator()
If you want unique random numbers, i.e. you want to shuffle the numbers 1 to 5'
Dim i, choice, balls(1 To 5)
Dim lngArr(1 To 5) As Long
Dim RwNdx1 As Long
Dim RwNdx2 As Long
Dim ColNdx As Long
Dim ColW As Long
Dim lrow As Long
Dim cnt1 As Long
Dim cnt2 As Long
Dim temp As Long
Dim Rng As Range
Dim ar As Range
Dim Cell As Range
With Worksheets("TL")
.Select
cnt1 = 1
cnt2 = 5
If cnt2 > 5 Then
End If
RwNdx1 = 3
RwNdx2 = 7
For ColNdx = 3 To 3
Randomize
For i = 1 To 5
balls(i) = i
Next
For i = 1 To 5
choice = 1 + Int((Rnd * (5 - i)))
temp = balls(choice)
balls(choice) = balls(6 - i)
balls(6 - i) = temp
Next
i = 0
With Cells(RwNdx1, ColNdx)
End With
Set Rng = Range(Cells(RwNdx1, ColNdx), Cells(RwNdx2, ColNdx))
For Each ar In Rng
For Each Cell In ar
i = i + 1
Cell.Value = balls(i)
Next
Next
Next ColNdx
End Sub
/Code
Thanks
Adam
Bookmarks