Results 1 to 3 of 3

Create random number when cell changes

Threaded View

Matt W Create random number when... 04-12-2011, 05:34 PM
Roger Govier Re: Create random number when... 04-12-2011, 05:50 PM
Matt W Re: Create random number when... 04-12-2011, 06:00 PM
  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Create random number when cell changes

    Hi. I am trying to create code that will generate a random number and place it in a specific cell when the drop down list selection in another cell in changed. If the selection in the drop down list is "" or "-", I want the cell with the random number to be blank. A new random number would be generated in the cell only if the drop down list selection changes.

    The code I have below does nothing as best I can tell, so I've obviously missed something. Any help would be appreciated!

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim Low As Double
    Dim High As Double
    Low = 100000
    High = 999999
    
    r = Int((High - Low + 1) * Rnd() + Low)
    
    If Not Intersect(Target, [F22]) Is Nothing Then
    On Error Resume Next
    Application.EnableEvents = False
    
    If F22 = "-" Or F22 = "" Then
        B20 = ""
    Else
        B20 = r
    End If
    
    Application.EnableEvents = True
    End If
    
    End Sub
    Last edited by Matt W; 04-12-2011 at 05:59 PM. Reason: solved

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