+ Reply to Thread
Results 1 to 4 of 4

vba to check if answer from 2 cells with =int(rand()*number) multiplied together is equal

  1. #1
    Registered User
    Join Date
    06-16-2013
    Location
    barry
    MS-Off Ver
    Excel 2010
    Posts
    7

    vba to check if answer from 2 cells with =int(rand()*number) multiplied together is equal

    Hi,

    Yeah i kno title doesn't give much away, but I didn't know how to word it.

    I am creating a worksheet with multiplication questions on. Using =int(rand()*15) in 2 cells. The user has to input their answers in the next column.
    Just had a thought, prob best just to use a formula to check scores are correct.

    Anyway my problem was using VBA to do a check if their answer matched the actual answers which were in a column in sheet 2. But I think VBA wasn't using the display values but the actual values 'behind the scenes'. Something strange was going on with the rand() formula because I wrote code in vba to display the answers from multiplying the 2 cells with the rand() formulas in and they were completely different, as if VBA picked its own random numbers itself.

    If anyone has an insight for future reference that would be awesome, but think I'll use a formula instead.

    One more thing, as I have these 2 cells with rand() formulas in to create the questions. Is there a setting to only run the rand() formula on open, because the questions will change on each user input otherwise.

    Thanks pals.

  2. #2
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: vba to check if answer from 2 cells with =int(rand()*number) multiplied together is eq

    have you tried using the VBA Rnd function instead of the Excel Rand()?

    alternatively, putting Application.Calculation = xlManual in appropriate part of the VBA code, and back to Automatic in other suitable place?

    alternatively putting Calculation to manual in Excel Options-->Formulas and pressing F9 when you want your formulae to calculate?

  3. #3
    Registered User
    Join Date
    06-16-2013
    Location
    barry
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: vba to check if answer from 2 cells with =int(rand()*number) multiplied together is eq

    thx for the manual calculations tip Kalak.

    Is the syntax for vba ran like excel rand. eg ran() * 10 will return value between 0 and 10.

    Can i also use int(ran()* 10) in vba.

    1 other thing. Are the names defined in excel name manager anything to do with variable names in vba.

    Thanks again Kalak

  4. #4
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: vba to check if answer from 2 cells with =int(rand()*number) multiplied together is eq

    Here's a VBA code that you can look at, read through and see if it provides useful information to you, or even run it if you like.

    It's not intended to do anything other than to try to clarify your questions
    .
    Please Login or Register  to view this content.
    Last edited by kalak; 06-18-2013 at 06:36 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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