+ Reply to Thread
Results 1 to 16 of 16

Change the value of a cell to 0 based on the value of another cell

  1. #1
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Change the value of a cell to 0 based on the value of another cell

    Hello,

    How can I Change the value of celsl to 0 based on the value of another cell.

    For example, if the value in cell A1 = "DN" then the value of B1:B6 = 0

    Thanks,

  2. #2
    Valued Forum Contributor mahju's Avatar
    Join Date
    11-27-2010
    Location
    Pakistan, Faisalabad
    MS-Off Ver
    Excel 2010 plus
    Posts
    730

    Re: Change the value of a cell to 0 based on the value of another cell

    Hi
    Use this formula

    Please Login or Register  to view this content.
    Regards

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Change the value of a cell to 0 based on the value of another cell

    Or

    =(A1="DN")*B1

  4. #4
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Change the value of a cell to 0 based on the value of another cell

    Thanks for your answers. But this formula will not do because I need to enter numbers in the cells in which you suggested to use this formula (B1:B6). If A1 = DN, I want the numbers in B1:B6 to change to 0. I think I need a macro to do this.

    Regards,,

  5. #5
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Change the value of a cell to 0 based on the value of another cell

    I'm using this code below. But there is something worng. Can anyone correct this code?



    Private Sub worksheet_change(ByVal target As Range)
    If [b3] = "DN" Then
    [C3:C5] = 0
    End If
    End Sub


    Regards,

  6. #6
    Registered User
    Join Date
    09-14-2004
    MS-Off Ver
    2010
    Posts
    30

    Re: Change the value of a cell to 0 based on the value of another cell

    I would try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Change the value of a cell to 0 based on the value of another cell

    Thanks a lot.

  8. #8
    Registered User
    Join Date
    09-14-2004
    MS-Off Ver
    2010
    Posts
    30

    Re: Change the value of a cell to 0 based on the value of another cell

    If this solved your problem, please don't forget to mark your thread as solved. (Edit your intial message, then click on "Go Advanced" and change the prefix for the message subject.)

  9. #9
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Change the value of a cell to 0 based on the value of another cell

    I'm trying to apply this code to different ranges. I'm using the code below, but it gives an error.

    Private Sub worksheet_change(ByVal target As Range)
    If Range("b3").Value = "DN" Then
    Range("C3:C5").Value = 0
    If Range("b10").Value = "DN" Then
    Range("C10:C15").Value = 0
    End If
    End If
    End Sub



    Can anyone help correct this code?

    Thank you,

  10. #10
    Registered User
    Join Date
    09-14-2004
    MS-Off Ver
    2010
    Posts
    30

    Re: Change the value of a cell to 0 based on the value of another cell

    What error is it giving you? Also the way it's written, if B3 is "DN", it will change C3:C5 and then it will check if B10 is "DN". If B3 isn't "DN", then it won't check B10 at all. If this isn't desired, I'd move one of the "End If"s to before the "If Range("b10")..." line.

  11. #11
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Change the value of a cell to 0 based on the value of another cell

    I tried to move of the End Ifs to before the "If Range("b10")..." line.
    When I enter DN in B3, C3:C5 is changed. But when I enter DN in B10, C10:C15 is changed but the excel workbook freezes and doesn't respond.

    I want what I mentioned but without the workbook freeze.

    Thanks,

  12. #12
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Change the value of a cell to 0 based on the value of another cell

    bkutkut

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  13. #13
    Registered User
    Join Date
    01-06-2011
    Location
    Riyadh
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Change the value of a cell to 0 based on the value of another cell

    I tried the code below. When I enter "DN" in B3, C3:C5 is changed to 0. When I keep "DN" in B3 and enter "DN" in B10, C10:C15 is changed to 0 AND the worksheet stops responding. It seems that there is a mistake in this code. Can anyone help correct this code?
    Here's the code:

    Please Login or Register  to view this content.

    Regards,

  14. #14
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Change the value of a cell to 0 based on the value of another cell

    See if this works for you
    Please Login or Register  to view this content.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  15. #15
    Registered User
    Join Date
    02-05-2019
    Location
    Bradford
    MS-Off Ver
    2016
    Posts
    15

    Re: Change the value of a cell to 0 based on the value of another cell

    Question posted as new thread.
    Last edited by Danielnir; 04-18-2019 at 09:41 AM.

  16. #16
    Valued Forum Contributor
    Join Date
    01-07-2013
    Location
    Michigan
    MS-Off Ver
    O365
    Posts
    601

    Re: Change the value of a cell to 0 based on the value of another cell

    I would start a new thread, with the relevant information regarding the code you're using. Pay attention to the Forum Rules (Rule #4 specifically).

+ 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