Results 1 to 8 of 8

Application.Volatile wont run in macro

Threaded View

EOD Application.Volatile wont run... 07-12-2010, 10:42 PM
shg Re: Application.Volatile wont... 07-13-2010, 12:27 AM
foxguy Re: Application.Volatile wont... 07-13-2010, 05:20 AM
EOD Re: Application.Volatile wont... 07-13-2010, 11:11 AM
foxguy Re: Application.Volatile wont... 07-13-2010, 01:29 PM
EOD Re: Application.Volatile wont... 07-13-2010, 05:08 PM
foxguy Re: Application.Volatile wont... 07-13-2010, 05:38 PM
EOD Re: Application.Volatile wont... 07-14-2010, 03:30 PM
  1. #1
    Registered User
    Join Date
    07-12-2010
    Location
    Niceville, Florida
    MS-Off Ver
    Excel 2003
    Posts
    7

    Application.Volatile wont run in macro

    Hello,

    So I work at a military school and need to random generate non-repeating numbers for test purposes. I found a macro that does what I need but it wont auto recalculate. I have tried adding in the Application.volatile but it does nothing for me. I know there are other ways of running the macro like a button and such but I need to simplify its use as much as possible for the less fortunate in the office who will use it. I will post the code below.

    Thank you

    Adam
    Sub DrawNumbers()
    'If you want unique random numbers, i.e. you want to shuffle the numbers 1 to 4
    '
    Dim i, choice, balls(1 To 4)
    Dim lngArr(1 To 4) 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
    
    ColW = ActiveSheet.UsedRange.Column - 1 + _
    ActiveSheet.UsedRange.Columns.Count
    
    lrow = ActiveSheet.UsedRange.Row - 1 + _
    ActiveSheet.UsedRange.Rows.Count
    
    ' Clear the existing data first
    Range("A1", Cells(lrow, ColW)).ClearContents
    Range("A1").Select
    
    cnt1 = InputBox("How many sets of numbers do you want?")
    cnt2 = InputBox("How many numbers in each set do you want?")
    
    If cnt2 > 4 Then
    Call DrawNumbers
    End If
    
    RwNdx1 = 2
    RwNdx2 = cnt2 + 1
    
    For ColNdx = 1 To cnt1
    Randomize
    For i = 1 To 4
    balls(i) = i
    Next
    For i = 1 To 4
    choice = 1 + Int((Rnd * (4 - i)))
    temp = balls(choice)
    balls(choice) = balls(5 - i)
    balls(5 - i) = temp
    Next
    
    i = 0
    
    With Cells(RwNdx1 - 1, ColNdx)
    .Value = "Set" & ColNdx
    .HorizontalAlignment = xlCenter
    .Font.Bold = True
    End With
    Last edited by EOD; 07-14-2010 at 03:32 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1