+ Reply to Thread
Results 1 to 6 of 6

Help with students math test

  1. #1
    Forum Contributor
    Join Date
    12-27-2021
    Location
    China
    MS-Off Ver
    Ms office 2019
    Posts
    188

    Exclamation Help with students math test

    Is it possible for VBA to meet my requirements? All instructions are included in the document. thanks
    Attached Files Attached Files

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help with students math test

    yes. try this:

    PHP Code: 
    Option Explicit
    Sub Math
    ()
    Dim r&, c&, rngsymb
    Const min 10 ' adjust to actual min value
    Const max = 20 ' 
    adjust to actual max value
    rng 
    Range("A2:H11").Value
    symb 
    = Array("+""-""*""/")
    Randomize
    For 1 To UBound(rng2)
        For 
    1 To UBound(rng)
            If 
    InStr(1"-1-4-7-""-" "-") And InStr(1"-2-6-10-""-" "-"Then
                rng
    (rc) = symb(Int(Rnd() * 4))
            ElseIf 
    InStr(1"-2-5-8-""-" "-") And InStr(1"-1-2-5-6-9-10-""-" "-"Then
                rng
    (rc) = min Int(Rnd() * (max min)) + 1
            End 
    If
        
    Next
    Next
    Range
    ("A2").Resize(UBound(rng), UBound(rng2)).Value rng
    End Sub 
    Attached Files Attached Files
    Quang PT

  3. #3
    Forum Contributor
    Join Date
    12-27-2021
    Location
    China
    MS-Off Ver
    Ms office 2019
    Posts
    188

    Re: Help with students math test

    Dear Bebo021999, thank you for your answer. But how can I increase the number of randomly generated rows? If I need 10, 20, or 100 lines, how can I modify the code? The current code can only generate 3 fixed lines

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Help with students math test

    Sorry for off-topic interjection:

    Although there is no official rule regarding this behavior, we request that wherever possible both the question AND the answer be provided in substantive detail here within the thread. An attached workbook is an excellent aid for posing a question and offering a solution, but solely doing that with no in thread explanation makes it difficult for researchers to understand or consider the Q & A of this thread without downloading what may be a pointless doc to them, if they can do that at all. Doing that also hides the content from search engines so others may never benefit from this.

    I'm sure you understand, and we look forward to seeing you post your formulas/macros in your posts for the searching benefit of all.

    Thanks again for all your hard work here!
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help with students math test

    again:

    PHP Code: 
    Option Explicit
    Sub Math
    ()
    Dim r&, c&, rngsymb
    Const min 10 ' adjust to actual min value
    Const max = 20 ' 
    adjust to actual max value
    Const setnum ' set numbers of math
    rng = Range("A2:H" & setnum * 4 - 1).Value
    symb = Array("+", "-", "*", "/")
    Randomize
    For r = 2 To UBound(rng) Step 4
        rng(r, 1) = symb(Int(Rnd() * 4))
        rng(r, 4) = symb(Int(Rnd() * 4))
        rng(r, 7) = symb(Int(Rnd() * 4))
        rng(r, 2) = min + Int(Rnd() * (max - min)) + 1
        rng(r, 5) = min + Int(Rnd() * (max - min)) + 1
        rng(r, 8) = min + Int(Rnd() * (max - min)) + 1
        rng(r - 1, 2) = min + Int(Rnd() * (max - min)) + 1
        rng(r - 1, 5) = min + Int(Rnd() * (max - min)) + 1
        rng(r - 1, 8) = min + Int(Rnd() * (max - min)) + 1
    Next
    Range("A2:J10000").ClearContents
    Range("A2").Resize(UBound(rng), UBound(rng, 2)).Value = rng
    End Sub 

  6. #6
    Forum Contributor
    Join Date
    12-27-2021
    Location
    China
    MS-Off Ver
    Ms office 2019
    Posts
    188

    Re: Help with students math test

    WOW, bebo021999, you are amazing!!! Thanks very much .

+ 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. Replies: 2
    Last Post: 09-21-2022, 02:25 PM
  2. How to extract the students' names that passed the test only
    By josh44 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-29-2019, 04:58 AM
  3. [SOLVED] Remove the Absent Students from the List of Failing Students
    By alyaahmed in forum Excel General
    Replies: 2
    Last Post: 03-28-2013, 01:40 PM
  4. Pull sub-test scores from test w/best overall test score (PSAT)
    By PowerSchoolDude in forum Excel General
    Replies: 0
    Last Post: 11-19-2009, 08:29 PM
  5. Replies: 1
    Last Post: 09-03-2008, 01:11 PM
  6. Replies: 3
    Last Post: 02-16-2006, 07:00 AM

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