If first 5 characters in cell are? then call macro

  • I have created a test generator that creates a bunch of questions inserting them into the next available cell in a worksheets row. As I go down the rows my question, its multiple choice answers and a listbox to pick the answers, are inserted into the next available cell. When a kid answers a question I want the number that they got correct to have a big check as clipart or a big x if it is wrong. I want the macro to do is go down column b, find the first character and if it is #1, insert check and so on. If the answer is for #2 I want it to find a 2 in the first character in column B.

  • Re: If first 5 characters in cell are? then call macro


    Chongo,


    Can you post your workbook? Adding a list box to each and every question may/may not be the best solution.


    A solution would be to have the student select the question to answer. A single list box ( combo box ) would align itself with the question. Fill itself with the designated answers. Then when the user selects a question it outputs to the proper cell based on the selected question cell.


    As far as the grading that would be simple as the listbox would do the grading as it goes.



    You would also need to check to see if a selected question had all ready been answered to prevent the student from selecting and selecting till he/she gets is right.

  • Re: If first 5 characters in cell are? then call macro


    You could probabaly do this with Data Validation. Post your example so that we can look at it.

  • Re: If first 5 characters in cell are? then call macro


    My workbook is very large. Could you give me an example of what you are talking about.

  • Re: If first 5 characters in cell are? then call macro


    Is there a way I can copy only a few characters from a textbox and paste them somewhere.
    For example if I had a paragraph typed into a textbox and I wanted to paste the first 128 characters into cell "B1". The characters 128-356 into cell "C1",
    The characters 356-484 into cell "D1". Is this possible?

  • Re: If first 5 characters in cell are? then call macro


    If you are using a TextBox and using VB, you could use this:


    Code
    Sheet1.Range("B1") = Left(Sheet1.TextBox1.Text, 128)
    Sheet1.Range("C1") = Mid(Sheet1.TextBox1.Text, 128, 228)
    Sheet1.Range("D1") = Mid(Sheet1.TextBox1.Text, 356, 128)
  • Re: If first 5 characters in cell are? then call macro


    Why did you use 128, 228 or 356, 128 I don't understand the characters that it is copying.

  • Re: If first 5 characters in cell are? then call macro


    based on your post,

    Quote

    I wanted to paste the first 128 characters into cell "B1"


    the first one looks at the first 128 characters.


    Quote

    The characters 128-356 into cell "C1"


    This code i have starting at character 128 and pulling 228 characters (which is the number of characters from 128-356)


    Quote

    The characters 356-484 into cell "D1".


    Same as last except starts at 356, and pulls 128 characters (which is the number of characters between 356-484)


    Hope this makes sense.

  • Re: If first 5 characters in cell are? then call macro


    Why didn't you just use right all the way instead of using Mid(. When would you use right( or would you

  • Re: If first 5 characters in cell are? then call macro


    Because you wanted the first 128 characters, so using left is easier when you are starting at character 1, and mid is for when you are starting in the middle of characters. If you wanted the Last 128 characters, I would have used the Right method.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!