Consulting

Results 1 to 7 of 7

Thread: Genrate simple calculations and check them

  1. #1
    Banned VBAX Regular
    Joined
    Oct 2008
    Posts
    14

    Genrate simple calculations and check them

    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)


    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:


    Step 5: The result of this test should be presented for the person in an Msgbox. It could look like this:


    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!"



  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Here you go try this file

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Doesn't work for me, RandBetween not a woksheetfunction method.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    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???
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    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
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This should be all you need

    [vba]

    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:C 12,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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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