1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Excel VBA: Subtract from a corresponding cell based on button placement

Discussion in 'Business Applications' started by rotvik, Oct 15, 2014.

Thread Status:
Not open for further replies.
Advertisement
  1. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    Hi guys,
    I need to write a macro that is connected to many buttons, one for each row in spreadsheet, ask for a value to subtract, error check and (if ok) subtract from a corresponding value in column P.

    When the button on a left hand side is clicked:

    • a dialog button should pop-up prompting a user to input the number of pieces to subtract from the corresponding cell (row based on the row of the button, column P)
    • error check the input number (show error if the value is smaller than 0 or larger than the corresponding value) ... I can write the error check by myself, so no need to do this step (y)
    • subtract the number from the corresponding cell (i.e. user clicked a button located in cell A9, input 9,24 pieces in a dialog box and there are 15,97 pieces in P9 => the pieces in P9 should change to 6,73)
    Thank you for helping me out! ;)
    Hope, the description is not very confusing.

    Michal
     
  2. CodeLexicon

    CodeLexicon

    Joined:
    Oct 15, 2013
    Messages:
    503
    You'll need to use the application.caller.row or application.caller.column to use the row / column number of the button in the macro
     
  3. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    I know. So far I have this from another macro:
    But don't know how to continue
     
  4. CodeLexicon

    CodeLexicon

    Joined:
    Oct 15, 2013
    Messages:
    503
    Ah, sorry, I thought that was your sticking point.


    What variable name(s) is/are assigned to the input number(s) (your example of "9,24")?
     
  5. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    I think it doesn't matter. Can be "c" or whatever.
     
  6. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    Hi guys,
    any ideas?
     
  7. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,553
    First Name:
    Hans
    How about a clear and explicit example, makes 'conversation' much easier :)
     
  8. rotvik

    rotvik Thread Starter

    Joined:
    Jan 11, 2013
    Messages:
    30
    After a really looong time, I've managed to write the following code:

    But I still have a problem with the "If PiecesInput >= 0 And PiecesInput <= Cells(Hcell.Row, Hcell.Column + 9).Value Then" part. Cells(Hcell.Row, Hcell.Column + 9).Value is i.e. 3000 but the macro doesn't work unless I write directly"If PiecesInput >= 0 And PiecesInput <= 3000 Then" (which would be incorrect for different rows).
    Any ideas on how to remedy this?
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1135464

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice