Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotate cells in Excel 1

Status
Not open for further replies.

mtdew

Technical User
Dec 9, 2007
77
US
I have a multiple choice quiz in excel where the question is in cell A, the correct answer in cell B and three other choices in cells C-E.

Is it possible to have a sheet that would display the question and rotate the answers so that the correct answer was not always the first one?

 



Hi,

This is not a VBA question. This is a native Excel feature: Format > Cells - Alignment Tab

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I don't see how this will help. When I look at Format - Cell - Alignment Tab the only options are Text Alignment, Text Control and Right-to-Left.

What I have now is:

A1 - question
B1 - right answer
C1 - incorrect answer
D1 - incorrect answer
E1 - incorrect answer

and I need for the cells B-E to vary so that the correct answer is not always found in cell B1. Or is there a way to compose a formula to say from these four cells display the data in various order?
 
You'll need some code to randomize the answers in columns B-E:
Code:
Public Sub RandomizeAnswers()
    Dim rg As Range
    Dim oldColumn As Integer
    Dim newColumn As Integer
    Dim correctAnswer As String
    
    Set rg = Range("B2:F2")
    Do While (rg(1) > "")
    
        newColumn = Int((4 * Rnd) + 1) 'Generate random value between 1 and 4
        
        ' Check to see if answers were previously randomized ...
        If (rg(5).Value > "" And IsNumeric(rg(5).Value)) Then
            oldColumn = Int(rg(5).Value)
        Else
            oldColumn = 1
        End If
        
        ' Swap answers ...
        correctAnswer = rg(oldColumn).Value
        rg(oldColumn).Value = rg(newColumn).Value
        rg(newColumn).Value = correctAnswer
        
        rg(5).Value = newColumn 'Place answer key in column F
    
        Set rg = rg.Offset(1)
    Loop
    
End Sub
 


Did you not see Orientation in that tab?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top