+ Reply to Thread
Results 1 to 17 of 17

Shuffle four answers of one question with a condition and loop it

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Shuffle four answers of one question with a condition and loop it

    In the attached excel file (version 2007), the first sheet is "quiz" and second sheet is "sheet1". It has a question/answer sheet (sheet1) that is designed in such a way that the first letter of the question is prefixed with the answer. For example here is a sample data in the range A1:A20 which is also attached. Answer to first question is "b" hence the question is prefixed with "b".

    bWho is a cricketer?
    Tiger Woods
    Sachin Tendulkar
    Will Smith
    Bill Gates
    aWho is a Golfer
    Tiger Woods
    Sachin Tendulkar
    Will Smith
    Bill Gates
    dWho is an Entrepreneur
    Tiger Woods
    Sachin Tendulkar
    Will Smith
    Bill Gates
    cWho is an actor
    Tiger Woods
    Sachin Tendulkar
    Will Smith
    Bill Gates

    I need to shuffle/jumble the four options for every question (in sheet1) whenever the workbook is opened without changing the logic of prefixing answer to the question's first letter and keeping all other things intact. Please help me how can I achieve this. What kind of code can be written and which section of vba (sheet/module)? Here is an example of question # 1 how it should be after randomization (on file open).


    cWho is a cricketer?
    Will Smith
    Bill Gates
    Sachin Tendulkar
    Tiger Woods


    Here, the options are shuffled/jumbled and also the correct answer is updated in the question (prefixed by 'c' which was earlier 'b'). I was looking at the chip article at http://www.cpearson.com/excel/ShuffleArray.aspx but I dont know how to implement this in my question. I also tried finding source on how we can make use of these functions by Chip that suits my question to no avail. I am still trying... even if i randomize the four options, how can i get the correct answer sequence (a, b, c, d) to prefix in the question is another tough task. Appreciate some help here. Thank you!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Shuffle four answers of one question with a condition and loop it

    You can try it like this:


    Questions with Randomized answers.xlsm
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    [QUOTE=Bernie Deitrick;3889286]You can try it like this:
    Thank you Mr.Deitrick. I appreciate your help and advising another approach to do it which is good enough. However, as mentioned in my first post, I need a solution without changing the logic of prefixing answer to the question's first letter and keeping all things intact. I have tried few other methods but I want to go with the one I described. I would be thankful if you can help me with that. All processing should happen only on one sheet (sheet1) without any use of formulas. The data I provided is just a sample data. The actual questions and answers are more...
    Last edited by freeofcost; 11-04-2014 at 05:44 PM.

  4. #4
    Forum Contributor
    Join Date
    12-18-2011
    Location
    long island
    MS-Off Ver
    365
    Posts
    236

    Re: Shuffle four answers of one question with a condition and loop it

    How about a random number generator and the choose function?

    Maybe this is a step in the right direction?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    Quote Originally Posted by phbryan View Post
    How about a random number generator and the choose function?

    Maybe this is a step in the right direction?
    Thank you Bryan.. I do not want to go with a worksheet function concept because on every activity the options would keep shuffling. But that should be fine and can be worked out. However, my problem is that, I already have a quiz ready and it shuffles the questions without any issues but does not shuffle the answers. The file is based on the format I described in my first post and therefore I do not want to go with a different concept/approach/logic. I was looking for help in getting the sheet1 data options to shuffle on workbook open event without formulas without changing anything. If sheet1 gets changed as per my desire then the file will be ready.

    Unfortunately I cannot do any logic change to the file because i will have to change a lot of things if I do so.
    The logic what I thought was when the file opens is that :
    1. It should take the first block of five rows (1question + 4 options),
    2. check the first letter of the question (1st row) and remember which answer it corresponds to and put it in a temporary variable. (In the example first letter is 'b' that means it corresponds to row 3 (Sachin Tendulkar)
    3. shuffle the four options (rows 2 to 5) and find where Sachin Tendulkar is from the first temporary variable and put it in another temporary variable.
    4. prefix and replace the first letter with the new position of Sachin Tendulkar (2nd temporary variable).
    5. loop it through all available questions in sheet1
    I think what I asked for can be done with vba but i am unable to do so inspite of several tries. Please help me if you can.
    Last edited by freeofcost; 11-04-2014 at 05:59 PM. Reason: added point no.5

  6. #6
    Registered User
    Join Date
    11-04-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Shuffle four answers of one question with a condition and loop it

    You mentioned that you "already have a quiz ready and it shuffles the questions without any issues but does not shuffle the answers". Can you post a spreadsheet with the quiz you have ready?

  7. #7
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    Quote Originally Posted by chris_davis View Post
    You mentioned that you "already have a quiz ready and it shuffles the questions without any issues but does not shuffle the answers". Can you post a spreadsheet with the quiz you have ready?
    Unfortunately I cannot because of license breach. The file is purchased with a license and I am modifying it. I have done a lot of modifications but the only thing left out is shuffling the answers without changing anything hence I posted here when I failed to do it. The only thing I can say is that if sheet1 data options are shuffled, my problem will be resolved.... Eagerly awaiting an answer. Thanks

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Shuffle four answers of one question with a condition and loop it

    If your column A is exactly like you showed, with the first set of questions and answers in A1:A5, then try:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    Quote Originally Posted by Bernie Deitrick View Post
    If your column A is exactly like you showed, with the first set of questions and answers in A1:A5, then try:
    Yes, it is exactly the way I had shown in my first post. Thank you so so so very much. Appreciate your assistance. God bless !

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

    Re: Shuffle four answers of one question with a condition and loop it

    Cross Posted here:
    http://www.mrexcel.com/forum/excel-q...ions-quiz.html

    A message to forum cross posters.

    Please read this:
    http://www.excelguru.ca/node/7
    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.

  11. #11
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    I completely agree... sorry about that. Infact I cross posted first time and was not aware of the rules. Henceforth I will keep it in mind. With all due respect, I never wanted to do anything wrong. My intentions were good and therefore I posted the answer so that coders should not put efforts on a solved question. I deeply regret the inconvenience.

  12. #12
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    @Bernie Deitrick Today I loaded 1000+ questions in the sheet. everything works fine with two issues:
    1. screen flickers for a very long time when it is randomizing set of every question - possible solution is to set the screen updating to false
    2. if the code is inserted in workbook open and before closing if the active sheet is different (not sheet1) then on opening, it gives error because the code works on activesheet - possible solution is to set the focus to shee1 on book open. Things becomes difficult if I hide "sheet1"
    My question is:
    1. can it be done in some kind of an array kept in memory and update the list when the calculation is over to get rid of screen flickering issue without using screen updating as a solution
    2. instead of setting the focus to sheet1, can the above calculation be done no matter which sheet is the active sheet?
    3. (Only if possible) a small alert saying "Loading questions. Please wait...." while the randomization is happening?

    Thank You.

  13. #13
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Shuffle four answers of one question with a condition and loop it

    This should speed it up and work on just "Sheet1" no matter which sheet is active, and it gives a small warning on the statusbar:


    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 11-05-2014 at 03:06 PM.

  14. #14
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    Well I already did it more or less the same way. Things which i didn't know how to implement was With Worksheets("Sheet1") and the .StatusBar
    I was hoping to know if there is any way to do it without the setting the screen updating to false. May be putting everything in an array, process the data (all question sets) and dump everything in the range at the end. The reason why I asked this is because, I had a bad experience an year ago where one vba program got halted in between somehow and the display alerts/events were permanently switched off. After a very long time we understood that the incident happened because of the halted program.

  15. #15
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Shuffle four answers of one question with a condition and loop it

    You can handle unexpected errors this way:

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 11-05-2014 at 03:59 PM.

  16. #16
    Registered User
    Join Date
    11-04-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    85

    Re: Shuffle four answers of one question with a condition and loop it

    Thanks again... I dont want to bother you but resume next can handle unexpected errors. What I meant was if the program stops not because of errors but due to some other factors such as power failure, computer problems or any other things then the display alerts/events should not get set to OFF for excel as an application. nevertheless, you have helped me a lot. I thank you once again. Have a great time. cheers!

  17. #17
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Shuffle four answers of one question with a condition and loop it

    Any time you shut down Excel and re-start it, events and screen updating are restored to the default On values, so computer problems should not be an issue with that code. And it should run fairly quickly, too.

+ 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. How do I get multiple answers for 1 question
    By Redwhite in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-17-2014, 05:32 AM
  2. Replies: 4
    Last Post: 08-21-2013, 04:58 PM
  3. If question returning 2 answers
    By P357 in forum Excel General
    Replies: 11
    Last Post: 08-29-2008, 10:44 PM
  4. Replies: 3
    Last Post: 04-01-2008, 08:31 PM
  5. Shuffle through sheets in a loop?
    By erikhs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-20-2006, 09:35 AM

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