+ Reply to Thread
Results 1 to 5 of 5

how to use cell value to define range/variable in vba

  1. #1
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    how to use cell value to define range/variable in vba

    dominicb posted this as an example of generating unique random numbers from a defined range 1-90
    so i thought i'd modify it fot use in a raffle
    code was
    Please Login or Register  to view this content.
    so after a bit of playing i thought
    if i changed this to
    Please Login or Register  to view this content.
    i could use it for raffle tickets, it seems to work ok
    but then i thought what if i only sell say tickets 200 to 599
    and only those to be selected, this is where i cant figure it out. ideally i'd like to be able to put start and end numbers of range in say a2/b2.
    and..................sorry.....a means of stopping it cleanly when all prizes given out. i know control brk works but is there another option?
    Last edited by martindwilson; 12-20-2008 at 05:53 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Here's an array function you can use to generate a random, non-repeating sequence from 1 to the number of cells in which the array formula appears:
    Please Login or Register  to view this content.
    If you want numbers from 200 to 599, then array-enter this into a 400-cell range:

    =RandSeq() + 199
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387
    martindwilson,

    My mistake.


    Have a great day,
    Stan
    Last edited by stanleydgromjr; 12-20-2008 at 06:03 PM.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    it doesnt like this
    Please Login or Register  to view this content.
    compile error expected end of statement!!!!!! then again im using '97

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    ps shhg tyhanks for th code nut!!!!!!!!!!!
    ok i took the dominicb one and reworked it like this
    Please Login or Register  to view this content.
    now what does the Dim rand1(2000) bit do?
    in the original it matched range of numbers but i found if i went too low say 10 it repeated so i arbitrarily put 2000 and it works fine
    i tried replacing it with "d" but it wont let me put a variable in there
    edit it doesnt work forsplit range sat 301-308 it returns 1thro 8
    Last edited by martindwilson; 12-21-2008 at 07:01 AM.

+ Reply to Thread

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