PDA

View Full Version : Genrate simple calculations and check them



gacid
11-01-2008, 07:30 AM
Hi! I've got a problem with a VBA-code.

Here it goes:

Step 1: I have to make 2 inputboxes, where you can choose an upper and lower limit for the numbers in the calculations (the calculations we want the VBA-code to generate in step 2).

Step 2: Here excel should generate 30 random calculations. 5 horizontal and 6 down. I have to like this image: (her is lower limit 10, upper 30)
http://imageload.dk/files/7a571463bc2502a0728f67e47f634cbf.JPG

Step 3: a person is manully calculating og inserting results.

Step 4: The VBA-code should now check if the results the person answered are correct. The calculations have to be run through and test:
1) how many correct answers
2) how many wrong answers
3) how many missing answers

I could look like this:
http://imageload.dk/files/6a92c2a83628e008a2070fc8fe1df98d.JPG

Step 5: The result of this test should be presented for the person in an Msgbox. It could look like this:
http://imageload.dk/files/ea4647df76b4bb3524a5c0046d6930ef.JPG

I know it's in danish ; )

Translated:

"There are 5*6 = 30 calculations and they are solved with following result:

26 correct answer(s).
1 missing answer(s)
3 wrong answer(s)

If you're not satisfied, then remember practice make champion!"

georgiboy
11-01-2008, 07:40 AM
Here you go try this file

Hope this helps :yes

Bob Phillips
11-01-2008, 08:50 AM
Doesn't work for me, RandBetween not a woksheetfunction method.

georgiboy
11-01-2008, 08:56 AM
I am using Excel 2007 do you think this might make any difference, because it works on my system. If i remove the worksheet.function part it throws up an error???

Bob Phillips
11-01-2008, 09:08 AM
You are right, it does work in 2007. It must be because it is an ATP function pre-2007, and ATP functions were amalgamated in 2007, so they must also have exposed it to VBA - I hadn't known that before.

georgiboy
11-01-2008, 09:13 AM
I dont mean to pass on work but i have little knowledge about this so if you could adjust my code to work on an older system it would be educating me and helping out gacid. I would greatley apreciate it :kiss

Bob Phillips
11-01-2008, 12:02 PM
This should be all you need



Sub AddRnd()
Dim SumRange As Range, rCell As Range
Dim Up, Lo As Integer
Dim tmp As Long

Application.ScreenUpdating = False

Lo = InputBox("Lower")
Up = InputBox("Upper")

Set SumRange = Range("C3,C3:C4,F3:F4,I3:I4,L3:L4,O3:O4,C7:C8,F7:F8,I7:I8,L7:L8,O7:O8,C11:C12,F11: F12,I11:I12,L11:L12,O11:O12,C15:C16,F15:F16,I15:I16,L15:L16,O15:O16,C19:C20 ,F19:F20,I19:I20,L19:L20,O19:O20,C23:C24,F23:F24,I23:I24,L23:L24,O23:O24")

For Each rCell In SumRange.Cells

If Val(Application.Version) > 11 Then

rCell.Value = WorksheetFunction.RandBetween(Lo, Up)
Else

tmp = Int(Rnd() * (Up - Lo + 1) + 1)
rCell.Value = tmp + Lo - 1
End If
Next

Application.ScreenUpdating = True

End Sub