+ Reply to Thread
Results 1 to 3 of 3

Smart Code Unexplained

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Smart Code Unexplained

    I got this code off of somebody on this site. It's supposed to randomly assign numbers to a range. It seems to work, but I don't understand the meaning of most of the code. If anyone feels like explaining how it runs, I'd appreciate it.




    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Smart Code Unexplained

    j gives a random integer between 1 and 20 (inclusive). If j turns up eg. 4 the first time, sel(4) will be 0 because everything in sel is zero except the first element which is 1. So after the loop sel(4) is set to 1 and cells(4,1) has the value 1. If 4 turns up again, the loop will carry on until it finds another value as sel(j)>0 (the loop ends when sel(j)=0). Hence at the end you get a set of random uniques from 1 to 20 (in this case).

  3. #3
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Smart Code Unexplained

    I'm starting to understand the idea. Here are the areas that confuse me. Wend seems to be a recognizable term to excel. What does it do?

    I've never seen anyone use this format with a variable
    Please Login or Register  to view this content.
    then a minute later
    Please Login or Register  to view this content.
    Is this a way that I'm not aware of of defining a variable? Why does the number in the parenthesis change?

    What is
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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