+ Reply to Thread
Results 1 to 4 of 4

change cell from positive to negative if adjacent cell is not blank

  1. #1
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    change cell from positive to negative if adjacent cell is not blank

    I have a coworker who is trying to use a formula to change the sign of a number in column G from positive to negative if anything is entered into the cell in column I of the same row. I've looked around for answers, and it seems that without using helper cells and other workarounds, the answer resides in VBA on the Worksheet_Change() event. I found the following snippet of code which may be a good starting point:


    Please Login or Register  to view this content.

    I made the following changes, as a starting point:
    Please Login or Register  to view this content.
    I'm assuming that putting this code in the "this workbook" object is the right location for the code...

    Also, I expect a change to the "G9" and "I9" cell references will be needed to make this code work on all rows... I also need it to be universal for the workbook and function on the active sheet, as she makes a new sheet every month for archival purposes.

    Let me know if I'm on the right track please. I've attached a sample workbook with the basic layout of the sheet... essentially all values in column G are entered as positives, and adding an "X" in column I (or any other charachter) should change the value in column G to a negative. Clearing the cell in column I should change the number in column G back to a positive.

    Please help! Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: change cell from positive to negative if adjacent cell is not blank

    Right Click On Your Sheet Name At the Bottom Of Excel and Select View Code
    Paste this code in the module that opens and close it.

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: change cell from positive to negative if adjacent cell is not blank

    That works perfectly, thanks!

    I tried putting it directly in the "This Workbook" module though, and it doesn't work there... but then I changed the event handler to this, and it works on all sheets:
    Please Login or Register  to view this content.
    Thanks! Way more elegant than the code I was trying to use... I love it when I can keep it simple!

  4. #4
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: change cell from positive to negative if adjacent cell is not blank

    Made one more adjustment, your code wasn't changing the number back to positive if the X was deleted, but this fixed it:

    Please Login or Register  to view this content.

    Now I'd call this one solved. Thanks again!

+ 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: 04-18-2017, 07:09 AM
  2. [SOLVED] Format cell colors based on another cell values with positive and negative numbers
    By rlowry in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-30-2017, 12:10 PM
  3. VBA Code to Make a Cell Value Negative Based on Content of Adjacent Cell
    By Court Manager in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2014, 04:18 PM
  4. [SOLVED] First Instance of a Negative and Positive Number in Adjacent Columns
    By 10OAKS in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-19-2013, 11:08 AM
  5. [SOLVED] Positive and negative cell count.
    By Big Rick in forum Excel General
    Replies: 4
    Last Post: 05-01-2012, 02:28 PM
  6. Replies: 2
    Last Post: 01-19-2009, 02:18 PM
  7. change cell from negative to positive
    By Terry in forum Excel General
    Replies: 1
    Last Post: 07-15-2005, 03:05 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