Consulting

Results 1 to 13 of 13

Thread: Solved: Teacher needs help in randomizing an answer into one of 4 multiple choice columns

  1. #1

    Solved: Teacher needs help in randomizing an answer into one of 4 multiple choice columns

    I need a routine that will go down a list of problems and place an answer into a randomized column.


    columns
    Cols = ___M_______N______O__P___Q__R______S_____W___X___Y
    Heads = Ques __Corr Lett__ A___F__B___T___act ans_res1_Res2_Res3
    row= __2+2=?_____ B______8___2__4___6_______4____2___8____6

    I have 100+ questions like 2+2=? in column M with the actual answer in Column S and three incorrect answers in column W,X,Y. Can someone help me with a routine that will go down the question list and do these things:
    1 Take the answer in col S and 10% of the time place it in column O under the heading A, 20% into col P, 30% into col Q and 40% into col R.
    2. then look at where the correct answer was placed and get the heading (A, F, B, T) and place it in column N.
    3. then take the incorrect responses in columns W,X Y and fill in the blank columns of O,P,Q or R.
    I just don't know enough about VBA to figure out this routine.
    Thanks

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Hi Sam62, In cases like this, it is far better to post a workbook with a befoe and after worksheets. That way we can play with the data to make sure it its your request.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3

    Thanks for the suggestion - here is the workbook

    Hope this mkes it easier for someone to see what will help my classroom, thanks

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    see attachment which contains this macro:[vba]Sub blah()
    Range("o2:r101").Clear
    For rw = 2 To 101
    myrnd = [RANDBETWEEN(1,10)]
    Select Case myrnd
    Case 1
    Cells(rw, "O").Value = Cells(rw, "S").Value
    Cells(rw, "N").Value = "A"
    Case 2, 3
    Cells(rw, "P").Value = Cells(rw, "S").Value
    Cells(rw, "N").Value = "F"
    Case 4 To 6
    Cells(rw, "Q").Value = Cells(rw, "S").Value
    Cells(rw, "N").Value = "B"
    Case Else
    Cells(rw, "R").Value = Cells(rw, "S").Value
    Cells(rw, "N").Value = "T"
    End Select
    i = 0
    For Each cll In Range(Cells(rw, "O"), Cells(rw, "R")).Cells
    If IsEmpty(cll) Then
    cll.Value = Cells(rw, "W").Offset(, i).Value
    i = i + 1
    End If
    Next cll
    Next rw
    End Sub
    [/vba]edited after you posted your workbook:So the columns are different as well as the percentages; to accomodate the percentages change, change
    [RANDBETWEEN(1,10)]
    to
    [RANDBETWEEN(1,100)]
    and
    Case 1
    to
    Case 1 to 15

    Case 2, 3
    to
    Case 16 to 35

    Case 4 To 6
    to
    Case 36 to 65

    You can change the column refs.
    Last edited by p45cal; 07-18-2009 at 05:23 PM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    or
    EDIT See below
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    mdmackillop, I don't see any difference between the file you posted and Sam62's - have I missed something?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks,
    I posted the wrong file. Now corrected.
    Regards
    Malcolm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    To P45cal and Mdmackillop,
    thanks both of you so much for your time and code. Here's what I found.
    P45cal - your file that I downloaded had all the values in the right place so I know it worked but no matter if I change the 10 to 100 and the case statements, when I run either version it debugs on the first Case line. But because I can see the results, I must be doing something wrong.
    Mdmackillop - thanks for sending back my file with the button on it - I place 200+ questions in and it built the columns the way I needed except for Column N where I needed to know what heading (AFBT) that the correct answer was placed in. Everything else worked.

    Thanks to both of you - could you tell me what you think I'm doing wrong?

    I found one thing -
    I notice that in the spreadsheet on U18, I mentioned that after placing the correct answer into one of the Columns AFBT then whatever column that correct answer went to (AFBT), then place that column's letter in column G - that was wrong, it should go into Column N under "Corr Let" - Maybe that is one reason why I didn't see the letters in one of the spreadsheets.
    Last edited by Sam62; 07-19-2009 at 12:26 AM.

  9. #9
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    re "I must be doing something wrong"

    While I can't look over your shoulder to see what's going on, might it be an idea to post your code?
    Last edited by p45cal; 07-19-2009 at 03:04 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I needed to know what heading (AFBT) that the correct answer was placed in
    Apologies, I missed that bit
    [vba]
    Select Case rnd1
    Case Is < 0.15
    cel.Offset(, -7) = "A"
    cel.Offset(, -4) = cel
    cel.Offset(, -3) = arr(0)
    cel.Offset(, -2) = arr(1)
    cel.Offset(, -1) = arr(2)
    Case Is < 0.35
    cel.Offset(, -7) = "F"
    cel.Offset(, -3) = cel
    cel.Offset(, -4) = arr(0)
    cel.Offset(, -2) = arr(1)
    cel.Offset(, -1) = arr(2)
    Case Is < 0.65
    cel.Offset(, -7) = "B"
    cel.Offset(, -2) = cel
    cel.Offset(, -4) = arr(0)
    cel.Offset(, -3) = arr(1)
    cel.Offset(, -1) = arr(2)
    Case Else
    cel.Offset(, -7) = "T"
    cel.Offset(, -1) = cel
    cel.Offset(, -4) = arr(0)
    cel.Offset(, -3) = arr(1)
    cel.Offset(, -2) = arr(2)
    End Select
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Thank you very much. I downloaded your code, mdmackillop, and changed 4 offsets from -7 to -5 and it works just the way I like. Thanks again. Thanks to P45cal too.

    Do I mark somewhere in this forum, "Solved" or not?

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Happy to help.
    Please be careful with your details
    except for Column N where I needed to know what heading (AFBT) that the correct answer was placed in.
    You can mark a thread solved using the Tread Tools dropdown.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Sam,
    Have you seen this site for teaching samples?
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •