+ Reply to Thread
Results 1 to 4 of 4

Excel Case/else structure math operations.

  1. #1
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Question Excel Case/else structure math operations.

    I am currently taking a class for Excel Vba, and have an assignment. I have tried everything I can think of, but can't get the calculations to work. In the AddUserInput procedure I am suppose to use a Select Case Structure to decide which math operation to use, also include a CASE ELSE to print an error message if an invalid math operation is entered by the user. I can get all of the inputboxes to show, but nothing happens and I don't know how to correctly format the Select case/case else structure. Any help would be greatly appreciated.


    Please Login or Register  to view this content.
    Last edited by vlady; 03-13-2013 at 07:35 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Excel Case/else structure math operations.

    Hi and Good Luck.


    Firstly as the main macro is defined as " Private" you can only call it from another macro. So not very useful.

    Secondly you have messed up the line that defines the mathoperation, mathoperation will always be zero.
    You should have used match or instr to convert the operation into a number.

    Thirdly you are not passing the mathoperation value to the subroutine that actually does the maths.
    Also why is it a subroutine?

    Fourthly I think that you may have misunderstood the use of the case function.

    I imagine that your tutor wants you to use the case function to carry ot a differrent operation on your variables based on the value of mathoperation.

    The only error messages you need are 1: Numeric Input only for the two variables. For that use isnumeric() to check if numeric if not a simple message box to say numeric only
    and loop back to the input box.

    2: when you check for operation, + - * or / if responce is N/A or 0 then message box to say + - * or / only
    and loop back to input box.

    You have a lot of work to do.

    I will help if you want. But I won't do it all for you.

  3. #3
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Excel Case/else structure math operations.

    I have been working on this literally all day. I made strmathoperation a string because that's what my directions said, "declare a string variable called MathOperation to hold the math operation to perform." And I have to use the select case/case else structure.


    Please Login or Register  to view this content.
    Again any help is much appreciated.
    Last edited by LadyB; 03-14-2013 at 12:55 AM.

  4. #4
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Excel Case/else structure math operations.

    I got the answer. Thanks for offering help.
    Last edited by LadyB; 03-14-2013 at 02:04 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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