+ Reply to Thread
Results 1 to 3 of 3

sub calling to a function

  1. #1
    Registered User
    Join Date
    11-15-2019
    Location
    israel
    MS-Off Ver
    2010
    Posts
    2

    sub calling to a function

    hello friends

    ithe vba is really new to me and I need some help.

    I did a simple sub that call to a function and it's not working

    can someone see what is the problem with it?

    thanks a lot


    Sub targillesson2()

    Dim I, ANSWER As Integer

    I = InputBox("chose a number for function")

    ANSWER = CHOOSE

    Debug.Print ANSWER

    End Sub



    Function CHOOSE(A, B)

    Dim RESULT As Integer

    Dim A, B As Integer

    A = 5
    B = 7

    If I = 1 Then
    RESULT = A + B

    If I = 2 Then
    RESULT = A * B

    If I = 3 Then

    RESULT = A - B

    If I = 4 Then
    RESULT = A / B

    End If

    CHOOSE = RESULT

    End Function

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: sub calling to a function

    As 1st. Please edit your post and use CODE tag to wrap your code.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    p.s. CHOOSE is already existed Excel function.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Registered User
    Join Date
    11-15-2019
    Location
    israel
    MS-Off Ver
    2010
    Posts
    2

    Re: sub calling to a function

    thanks a lot!!

+ 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. [SOLVED] Multiple Main Function calling one sub function in different ranges
    By LukeNZ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2019, 04:26 PM
  2. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  3. Replies: 5
    Last Post: 09-15-2014, 12:41 AM
  4. Macro exits prematurely from function after calling other function
    By LouisPhilippe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 03:22 AM
  5. [SOLVED] help with calling a function (B) and return control of program flow to the calling functio
    By john/nyc in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-26-2012, 11:06 AM
  6. Calling my function in VBA
    By jasonjenkinson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2006, 10:04 AM
  7. [SOLVED] calling a function
    By dmexcel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-23-2006, 08:10 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