+ Reply to Thread
Results 1 to 10 of 10

Autosubtracting a value from same cell a manual entry is made

  1. #1
    Registered User
    Join Date
    03-02-2011
    Location
    IL
    MS-Off Ver
    Excel 2003
    Posts
    6

    Autosubtracting a value from same cell a manual entry is made

    Hello, i cannot seem to figure out how to make a cell subtract 2.1 from a number that i enter in the cell automatically. i want the cell to be blank until i manually enter a number, press enter, then the result is the number i entered - 2.1. i have attached what I’ve got so far along with an explanation. also on another sheet i have a similar problem but a little bit more complicated, so i tried explaining it on the sheet. any help would be appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Autosubtracting a value from same cell a manual entry is made

    Hi tony324 and welcome to the forum,

    Let me try to explain what's happening.

    In a single cell there can exist a formula or a number. The formula might show a number but it is really a formula in the cell. If you have a formula in cell A1 like = A1 - 2.1, Excel will complain and say you can't do that (circular referencing) because formulas need a typed in number to work with.

    So lets fix your problem. In A1 put a NUMBER like 200. Now in B1 put a formula like = A1 - 2.1 and press enter. This will show the answer you are looking for.

    This seems easy enough but you want too much.

    A work a round. How about having two identical looking tables on two different sheets. On Sheet 1 is where you put youir "Real" numbers and on Sheet 2 you have your formulas.

    So if on Sheet1 in Cell A1 you have 200, on Sheet2 in A1 youir formula would be =Sheet1!A1 - 2.1
    This method will work but will take two sheets.

    Another alternative would be to write VBA Event Code looking at each cell on your sheet. Whenever you entered a number it would grab that number and do the math and stick that number back in the cell. If you were to put a space after an already entered number it would do the math on it again, and again and again.. I don't think you want to do Events in VBA.

    I hope this helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Autosubtracting a value from same cell a manual entry is made

    hi, tony324, please check attachment, sheet "MSH" is done, it it's ok we'll move to the rest, the value subtracted will be taken from cell B21
    Attached Files Attached Files

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Autosubtracting a value from same cell a manual entry is made

    Hi again,

    Using watersev's code, put a number in a cell and press enter. It really does subtract 2.1 just like you wanted.

    Now select that cell again and put the cursor up in the formula bar and press enter. Whoops, it subtracted 2.1 again. Did you want it to do that? If you did then great!

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Autosubtracting a value from same cell a manual entry is made

    @MarvinP a bit strange way to insert values into a cell through formula toolbar .... usually users input everything directly in the cell however that's a weak spot for this particular idea
    Last edited by watersev; 03-03-2011 at 11:53 AM.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Autosubtracting a value from same cell a manual entry is made

    Not only entering from the formula bar but copy and paste the value to another cell. Also try autofil by dragging the entered number down.

    All of a sudden the "normal" excel methods seem to change.

    I like your code, and it works but I think an understanding of circular references was the topic needed for this user.

    BTW - Where did you learn [b21] = Cells(21,"B") = Range("B21") ? I like Cells but could get used to the Evaluate "[ ]" method as it is easier to type.

  7. #7
    Registered User
    Join Date
    03-02-2011
    Location
    IL
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Autosubtracting a value from same cell a manual entry is made

    MARVIN": thanks that is an option, and i may use that in the future or if "WATERSEVs" doesn’t work out down the line.

    WATERSEV" wow, i wish i knew how to do things like that, that works great. if you could do that to the other sheet it would greatly appreciate it. Thanks again.

    Side note, how long does something like this take you to write out? and what exactly is the process your doing called? i know how to access the codes? (if thats what they are called) by pressing alt F11, but how does one learn what to put in that screen.
    i am really amazed by all of this and i hope to learn just a fraction of it some day.

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Autosubtracting a value from same cell a manual entry is made

    see attachment, it looks better now in terms of mentioned above weaknesses: copying, formula bar, dragging, double-click etc.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Autosubtracting a value from same cell a manual entry is made

    please check attachment, the second sheet done as well.

    Quote Originally Posted by tony324 View Post
    Side note, how long does something like this take you to write out?
    It depends on the writer
    and what exactly is the process your doing called?
    It's worksheet_change event triggered by changes on this particular sheet
    i know how to access the codes?
    Press ALT+F11, CTRL+R, on the left you will see the workbook name, sheets and modules.
    (if thats what they are called) by pressing alt F11, but how does one learn what to put in that screen.
    There are many books on that as well as online courses.
    i am really amazed by all of this and i hope to learn just a fraction of it some day.
    @MarvinP: I can't remember exactly, it was in someone's code in the Internet
    Attached Files Attached Files
    Last edited by watersev; 03-04-2011 at 04:44 AM.

  10. #10
    Registered User
    Join Date
    03-02-2011
    Location
    IL
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Autosubtracting a value from same cell a manual entry is made

    thanks alot!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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