+ Reply to Thread
Results 1 to 2 of 2

RandBetween - No Duplicates in Column

  1. #1
    Registered User
    Join Date
    07-11-2018
    Location
    Homer, MI
    MS-Off Ver
    2016
    Posts
    1

    RandBetween - No Duplicates in Column

    Hi Everyone,
    I'm new to this forum, but do have some VBA experience. However, I'm struggling to figure out how to get this code to give random values between 1 and 57. There are a total of 31 rows, and 53 columns (one column for each week of the year). What I'm looking for is some help to tweak this code where there are no duplicates within the column, but it's okay if there are duplicates in a row.

    PLEASE HELP!


    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim cell As Range
    Dim Schedule As Range
    Set Schedule = Range("B2:BB31")

    If Target.Address = "$A$1" Then

    For Each cell In Schedule
    cell.Formula = WorksheetFunction.RandBetween(1, 57)
    Next cell

    For Each cell In Schedule
    cell.Activate
    If Application.WorksheetFunction.CountIf(Schedule, ActiveCell) > 1 Then
    Do
    ActiveCell.Formula = WorksheetFunction.RandBetween(1, 57)
    Loop Until Application.WorksheetFunction.CountIf(Schedule, ActiveCell)
    End If
    Next cell

    End If
    End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: RandBetween - No Duplicates in Column

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Reverse Raffle setup: using Randbetween without duplicates
    By msauer in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-23-2018, 05:35 PM
  2. Separation of duplicates with RANDBETWEEN
    By wyturieowk in forum Excel General
    Replies: 1
    Last Post: 04-30-2017, 03:18 PM
  3. [SOLVED] Randbetween with No Duplicates
    By novice1239 in forum Excel General
    Replies: 6
    Last Post: 03-19-2017, 10:17 AM
  4. Replies: 10
    Last Post: 07-03-2015, 04:29 PM
  5. How do you avoid duplicates when using the randbetween function?
    By Monica in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-28-2014, 02:07 AM
  6. Randbetween without duplicates
    By Williamdry in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-29-2014, 09:27 AM
  7. [SOLVED] =RANDBETWEEN Function for growing price list with no duplicates...
    By unclejemima in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-18-2013, 03:29 PM

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