Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 4 alternatives to all questions need randomization

In my 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. 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 am not able to implement this in my question. I also tried finding source on how we can make use of these functions 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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 4 alternatives to all questions need randomization

I got an answer at excelforum and thought I should update the link http://www.excelforum.com/excel-prog...d-loop-it.html
Thank you

Sub test()
Dim r As Long
Dim CA As String

For r = 1 To Cells(Rows.Count, "A").End(xlUp).Row Step 5
CA = Cells(r, "A").Offset(Asc(LCase(Left(Cells(r, "A").Value, 1))) - 96, 0).Value
Cells(r, "A").Offset(1, 1).Resize(4, 1).Formula = "=RAND()"
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Cells(r, "A").Offset(1, 1).Resize(4, 1), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Cells(r, "A").Offset(1, 0).Resize(4, 2)
.Header = xlNo
.Orientation = xlTopToBottom
.Apply
End With
Cells(r, "A").Offset(1, 1).Resize(4, 1).Clear
CA = Chr(Application.Match(CA, Cells(r, "A").Offset(1, 0).Resize(4, 1), False) + 96)
Cells(r, "A").Value = CA & Right(Cells(r, "A").Value, Len(Cells(r, "A").Value) - 1)
Next r
End Sub


On Tuesday, November 4, 2014 9:04:34 AM UTC+5:30, Rajnish Malhotra wrote:
In my 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. 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 am not able to implement this in my question. I also tried finding source on how we can make use of these functions 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!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - randomization with certain criteria Alen Paliska Excel Worksheet Functions 3 May 16th 07 06:41 PM
Data Randomization Hannie1004 Excel Worksheet Functions 2 February 16th 06 06:50 PM
Randomization of groupings based on value Ouka[_28_] Excel Programming 1 January 5th 06 04:39 AM
strange randomization William Benson[_2_] Excel Programming 13 October 10th 05 09:54 PM
Randomization of Multiple Columns and Sequences Sandy Pasdak Excel Programming 1 July 30th 03 04:54 AM


All times are GMT +1. The time now is 02:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"