+ Reply to Thread
Results 1 to 3 of 3

Create a button to subtract cells in one row from another

  1. #1
    Registered User
    Join Date
    03-12-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    21

    Create a button to subtract cells in one row from another

    Is there any way I can create a button which when clicked will subtract the values in one row from another row? For example:

    A 1 1 1 1 1
    B 2 2 2 2 2

    I'd like to create a button which when clicked, will take each cell in the B row, and subtract the corresponding A cell from the B cell, i.e. in the example, the button when clicked will leave 1,1,1,1,1 in the B row. I would also like no action to be taken if the A row is empty. Is this a job for a macro, or would I need some code to do what I want?

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Create a button to subtract cells in one row from another

    Macro solution, try this

    Please Login or Register  to view this content.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  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,721

    Re: Create a button to subtract cells in one row from another

    This code is based on the above and has the following enhancements based on the description in the OP.

    1. Declares all variables
    2. Does not perform an operation if the cell in the first row is blank
    3. Updates the values in the second row (code above adds a new row with the results)
    4. Subtracts the value in the first row from the value in the second row (code above does the reverse)
    5. Starts in column B, assuming column A is reserved for some kind of label as shown (code above starts in column A) (However, the OP may be a little confused as the row labels in the post are A and B)


    Please Login or Register  to view this content.
    You can create a button then associate this code with the button.

    Note that this code does exactly what your example shows. It always operates on columns B:F, always in rows 1 and 2. If you want to operate on the currently selected row, or operate on however many cells are in the row instead of a fixed number of columns, the code needs to be updated.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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] create a 'button' to click to clear cells
    By OAKLEY in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-13-2014, 07:12 AM
  2. Replies: 0
    Last Post: 12-19-2011, 01:09 PM
  3. Need to create a button that can copy cells, create a new sheet and then paste there
    By torontoguy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-14-2009, 11:26 AM
  4. Create a button to clear data in certain cells
    By headbanger51 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-07-2008, 03:18 AM
  5. [SOLVED] Create a button to Clear Cells
    By tamato43 in forum Excel General
    Replies: 3
    Last Post: 05-15-2005, 10:06 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