+ Reply to Thread
Results 1 to 12 of 12

Macro to ask for two figures and subtract the first figure from the second and input that

  1. #1
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Macro to ask for two figures and subtract the first figure from the second and input that

    Hi,

    I amlooking for a macro that opens an input box asking for 2 figures. These figures aren't to be shown anywhere in the worksheet they are just to subtract the first from the second and then input the result.

    I am guessing the best way to do it is an input box but not sure if that can do it as I wish?

    Also, I would need the macro to start up on the click on the cell not as a command button as there are other cells that autopopulate in the workbook. This would be done in A2 and then A3 etc.

    EDIT: There could be more than 1 sum too. So it could be 2 results of sums to be added together after.


    Thanks in advance

    Daniel
    Last edited by DannyJ; 05-06-2015 at 08:31 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,806

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Hi Daniel. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Click any cell in Column A. You will be prompted to enter the two numbers and the result will be placed in column B.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Try this too see if you can use it. It operates on Sheet1 by Double-Clicking in A2.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Thank you John and Mumps. I have test Mumps' code and that does the job. Would it be possible to maek this occur for more than 1 set of numbers so for example "Number 2 - Number 1" and "Number 4 - Number 3" and then add the 2 figures together?

    Would it be possible to make z input into column A John and the same with regards to multiple sums?

    Thanks for the quick replies.

    Danny

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Maybe:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Thank you John,

    That now works for a single sum. Is it possible to make it so there is an option for 2 sums to be done and add the results together?

    Thanks,

    Danny

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Does this help?

    Please Login or Register  to view this content.
    Changed click cell to A1.

  8. #8
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    That is almost there John. Sorry, I am not being clear. It would be input two values, call them x and y and then y - x = z.

    Then the second time it would be a and b. b - a = c

    Then c+z is the value input into column a. All as one vba code and just one figure output at the end.

    Thanks for the replies .

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Confusing too me. Try one of these:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-06-2015 at 02:54 PM.

  11. #11
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    Thank you jindon and John they both work. (John the top one worked for me ) really appreciated the help guys

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to ask for two figures and subtract the first figure from the second and input t

    You're welcome. Glad to help out and thanks for the feedback. Please mark this thread as SOLVED.

+ 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. Replies: 4
    Last Post: 02-03-2014, 08:05 AM
  2. [SOLVED] Input box: can't figure out how to activate that selection for hte rest of the macro
    By charles1394 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2013, 11:04 PM
  3. I am trying to figure out how to subtract time.
    By childers2 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-03-2012, 03:29 PM
  4. Cant Figure out how to program macro to input data into 2nd worksheet
    By robnez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2012, 05:12 AM
  5. [SOLVED] Calculating a YTD figures from changing monthly figure.
    By rGrant in forum Excel General
    Replies: 5
    Last Post: 05-16-2006, 09:55 PM

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