+ Reply to Thread
Results 1 to 7 of 7

Use Inputbox answer to be used in another sub procedure

  1. #1
    Registered User
    Join Date
    03-08-2015
    Location
    Cebu, Philippines
    MS-Off Ver
    2013
    Posts
    3

    Use Inputbox answer to be used in another sub procedure

    First of all, I am not an expert when it comes to VBA codes so please simplify your answers.

    We are asked to make a program that budgets money. The first part of the program is an assessment. One of the questions is "Do you want to limit your food allowance?". I tried using a yes and no option button. If the user clicks YES, an inputbox will appear asking for the amount. I want to use that amount for another sub procedure because the last part of the assessment is a SUBMIT button. The amount inputted in that inputbox will be used. How do I do that? I've tried making it into a function but I'm having a hard time since it is an option button. Thank you in advance.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Use Inputbox answer to be used in another sub procedure

    Use a Public variable. For example:
    Please Login or Register  to view this content.
    Gary's Student

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Use Inputbox answer to be used in another sub procedure

    Using a global variable will work perfectly well, although the best programming practice is to pass data as parameters. Global variables create common data coupling, a method of tight coupling which can introduce bugs that are very difficult to diagnose in more complex programs.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    03-08-2015
    Location
    Cebu, Philippines
    MS-Off Ver
    2013
    Posts
    3

    Re: Use Inputbox answer to be used in another sub procedure

    Thank you for replying. I am not sure if I'm correct.

    Please Login or Register  to view this content.
    The first one runs in the main SUBMIT button. The second one runs if an option button button is clicked. If I use "call", would it run the inputbox again? I don't want running the inputbox again.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 03-14-2015 at 11:47 AM.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Use Inputbox answer to be used in another sub procedure

    We need to see more of your solution. Can you attach your workbook?

    To attach a file:
    1. Under the text box where you type your reply click the Go Advanced button.
    2. In the next screen look above the reply box and click the "paper clip" icon. You will get a pop-up screen.
    3. In the pop-up, click Add then Select to select a file from your local drive
    4. Click the Upload button to upload the file
    5. Click Done to attach it.

    It will be displayed as an attachment underneath your post text. Alternatively as the last step you can click the Insert Inline button and a hyperlink to the file will be inserted directly into your post text in the spot where your cursor is set at the moment you click the button.

    Here are step-by-step instructions with screen shots

  6. #6
    Registered User
    Join Date
    03-08-2015
    Location
    Cebu, Philippines
    MS-Off Ver
    2013
    Posts
    3

    Re: Use Inputbox answer to be used in another sub procedure

    Budgetting PROGRAM.xlsm

    THANK YOU SO MUCH FOR REPLYING!
    This is my workbook. I haven't gone to the major part yet because I'm stuck with my problem.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Use Inputbox answer to be used in another sub procedure

    After seeing what you are trying to, I will reverse myself and tell you to use global variables. This is because you need persistent variables--you are saving them for later, not just passing them around.

    It looks like you have some confusion here. You have the question about transportation allowance duplicated. Your code references the top one. I also suggest you add a "Close" button, or call Hide after the user hits Submit.

    Note that this uses Application.InputBox, as shown by Jakobshavn, otherwise you can't use the Type argument. Type:=1 requires the user to enter a number.

    Please Login or Register  to view this content.

+ 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] Answer for inputbox
    By juriemagic in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2014, 03:11 AM
  2. [SOLVED] Automatically answer InputBox
    By rnd37 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-17-2012, 09:34 AM
  3. InputBox-ow to have a user input text in a inputbox
    By noodle48 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2011, 08:17 AM
  4. Inputbox button control + msgbox for empty inputbox
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2009, 12:39 PM
  5. [SOLVED] Within the same procedure, can such Inputbox be used more than onc
    By Edmund in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2006, 04:00 AM

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