Results 1 to 16 of 16

Randomly assign codes to cells

Threaded View

  1. #1
    Registered User
    Join Date
    05-10-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    11

    Randomly assign codes to cells

    Bit of a complicated one and I have no real idea if it can even be done. I have a spreadsheet of students (213 of them) and the classes they take during different periods (i.e. column one is the list of students, then the columns afterwards are Monday P1, Monday P2 and so on). There is a two week timetable too.

    Some periods don't have any data in, because they have a free period, but I need to randomly assign two specific study periods (using an ICT suite) per student.

    However, there can only be a certain number of kids in the study period due to the lack of computers! I essentially want to allocate two study sessions per row (i.e. per student), but without having 86 students attending one study session (for example), and only four in the second. I fear that there are too many variables and I'll have to do it the old fashioned slow way.

    Any ideas how it could be done?

    I did try the following:
    Sub ss()
    
    Dim MyRange As Range
    Dim MyColumn As Long
    Dim MyMin As Long
    Dim MyMax As Long
    Dim MySwitch As Long
    
    MyMin = 4
    MyMax = 63
    MyVar = MyMin
    MySwitch = 0
    
    Do Until MyVar = MyMaxSet MyRange = ActiveWorkbook.Worksheets("Sheet1").Range(Cells("A2", MyVar), Cells("A214", MyVar))
    For Each cell In MyRange.Cells
    Select Case MySwitch
    Case 0
    If cell.Value = "" Then
    cell.Value = "Study session 1"
    MySwitch = MySwitch + 1
    End If
    Case 1
    If cell.Value = "" Then
    cell.Value = "Study session 2"
    MySwitch = MySwitch - 1
    End If
    Case Else
    MsgBox "An error has occurred"
    End Select
    Next
    MyVar = MyVar + 1
     Loop
    
    End Sub
    but this doesn't work (my first attempt at a macro!). I've attached the file as I'm not sure if I've made sense!
    Attached Files Attached Files
    Last edited by Gemsie; 09-27-2013 at 05:38 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Use Excel to randomly assign teams to sports competitions
    By Waldo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-09-2013, 02:10 AM
  2. Randomly assign a value to rows
    By covegolfer in forum Excel General
    Replies: 3
    Last Post: 06-13-2011, 12:29 PM
  3. Randomly (and evenly) assign colors to cells
    By JChandler22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2010, 05:22 PM
  4. [SOLVED] How to assign value using a Char Codes?
    By CRayF in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2005, 07:05 PM
  5. How do I randomly assign values in a grid?
    By Excel question in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2005, 08:05 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