Results 1 to 4 of 4

Excel Case/else structure math operations.

Threaded View

LadyB Excel Case/else structure... 03-13-2013, 06:19 PM
mehmetcik Re: Excel Case/else structure... 03-13-2013, 06:40 PM
LadyB Re: Excel Case/else structure... 03-14-2013, 12:39 AM
LadyB Re: Excel Case/else structure... 03-14-2013, 01:58 AM
  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.


    Option Explicit
    
    Dim answer As Integer 
    Dim num1 As Integer
    Dim num2 as Integer
    Dim Mathoperation As String
    
    Private Sub Main()
    
        num1 = Val(InputBox("Please enter the first operand", "First operand"))
        num2 = Val(InputBox("Please enter the second operand", "Second operand"))
        Mathoperation = Val(InputBox("+,-,*, or / for math operation", "Math Operation"))
    
        Call AddUserInput(num1, num2)
        SendResult
    End Sub 
    Private Sub AddUserInput(num1 As Integer, num2 As Integer)
        answer = num1 + num2
    End Sub  
    Private Sub SendResult()
        MsgBox ("The answer is " & Str(answer))
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Call Main
    End Sub
    Last edited by vlady; 03-13-2013 at 07:35 PM.

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