+ Reply to Thread
Results 1 to 32 of 32

Change value in column based on value in other column

  1. #1
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Change value in column based on value in other column

    I'm trying to use the following formula but not getting the desired results:

    Please Login or Register  to view this content.
    If a value in column J is set to "Y" I'd like to the change the value in the same row but corresponding column CB to "WORK"

    Thanks!

    M
    Last edited by SHUTTEHFACE; 12-11-2014 at 04:46 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Thanks!

    Would you mind walking me through the logic?

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Would you mind walking me through the logic?
    When working your range of values you will need to have some way of isolating the values of each cell within the range. There are a couple of ways of doing this such as looping or filtering. I choose filtering to solve your problem. I have added comments to the code to help clarify its purpose

    Please Login or Register  to view this content.
    Another less efficient, but possibly more understandable, technique would be something like this
    Please Login or Register  to view this content.
    Last edited by stnkynts; 12-11-2014 at 05:55 PM.

  5. #5
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Awesome thanks!

    If I wanted to modify this to include values that were "N" and have the listed as "OFF" in CB would the code then be:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Yes that should work just fine.

  7. #7
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Awesome, now let's say I had to do the same thing but also including the values in column K,L,M,N,O,P which each have their respective columns EF,GJ,IN,KR,MV,OZ to change to "OFF" or "WORK". Do I just duplicate the above With statement for each one or is there a more efficient way?

  8. #8
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Is there any reason why you can't just use formulas in the output columns? I.E. =IF(J2="Y", "WORK", ""). Then just fill down the column.

  9. #9
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Ah, I'm doing this because I am using them as data validation cells as well. I wanted to have the functionality of changing the individual cell to "OFF" or "WORK" as well as change it based another cell input.

  10. #10
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    I tried the following but it doesn't work correctly.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Try this:

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Awesome, almost works flawlessly! When I change the values to Y or N, the values in the corresponding column and row are changing correctly but it is also adding "OFF" to the first row for each of those columns.

  13. #13
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Woops. I forgot to exclude the first row. Change this line

    Please Login or Register  to view this content.
    to this

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Changing this gave me an error with this line in debug "No cells were found":

    Please Login or Register  to view this content.
    Could it be because all the input and outputs happen below row 7?
    Last edited by SHUTTEHFACE; 12-12-2014 at 03:09 PM.

  15. #15
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    I've attached a demo version of my spreadsheet so you can get a better idea of what I'm trying to do. I can't seem to get this code working properly.

    Thanks for the help!demo.xlsm

  16. #16
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    It error because there were situations in which you didn't have both a "n" and "y" as a filter parameter. The below code is amended for that along with the location of the header. Keep in mind that this code should not be part of the worksheet_change event as you have it and should instead be its own stand alone subroutine. Lastly, you worksheet_change code with either vastly slow down the code or potentially cause more errors along the way:

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Thanks stnkynts!

    What would you suggest I do in the worksheet_change code to speed up the code? I'd like to have it where is someone changes the individual day to "WORK", "OFF", "PTO", the following cells populate accordingly, either with the default schedule or blank if OFF OR PTO is set. The current code I have under workbook_change was supposed to allow me to do this.

  18. #18
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Quote Originally Posted by stnkynts View Post
    It error because there were situations in which you didn't have both a "n" and "y" as a filter parameter. The below code is amended for that along with the location of the header. Keep in mind that this code should not be part of the worksheet_change event as you have it and should instead be its own stand alone subroutine. Lastly, you worksheet_change code with either vastly slow down the code or potentially cause more errors along the way:

    Please Login or Register  to view this content.
    A couple questions:

    1. How can I modify this code to change the cells to the right as well as the "WORK" & "OFF" cells. So if we set it had Y for Monday it would populate both "WORK" and the default schedule for each of the following 5 cells.

    2. The values for column "P" needs to change the values for X as well as OZ. It currently only updates OZ.

    Thanks!

  19. #19
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    What would you suggest I do in the worksheet_change code to speed up the code? I'd like to have it where is someone changes the individual day to "WORK", "OFF", "PTO", the following cells populate accordingly, either with the default schedule or blank if OFF OR PTO is set. The current code I have under workbook_change was supposed to allow me to do this.
    Your existing worksheet_change code isn't bad or wrong. The problem occurs when you run the macro I wrote. On some circumstances it will cause the worksheet_change to trigger. You may or may not want this. I don't know what your goal is so I wasn't sure if I should have disabled the worksheet_change event from triggering in my macro (you can do this through Application.EnableEvents). If I was guessing I would do something like this (once again I am not sure what you flow is so it is up to you to understand what is going on and whether to implement this strategy or not.)

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  20. #20
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    1. How can I modify this code to change the cells to the right as well as the "WORK" & "OFF" cells. So if we set it had Y for Monday it would populate both "WORK" and the default schedule for each of the following 5 cells.
    I have no idea what the default schedule is but you would do it by editing/or including another line of code for the required cell offset from rOutput

    2. The values for column "P" needs to change the values for X as well as OZ. It currently only updates OZ.
    Like this:
    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Thanks, tried the following but getting an error at

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  22. #22
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    This is wrong

    Please Login or Register  to view this content.
    What is it supposed to be?

  23. #23
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    I'm trying to define column Q and the row in which the current operation is taking place. If

    Please Login or Register  to view this content.
    Then the following cell needs to be equal to the cell located at column Q and the row modified.

  24. #24
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Any ideas?

  25. #25
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Please Login or Register  to view this content.
    Getting "no cell were found" error at

    Please Login or Register  to view this content.
    Is this because the value of the cell is blank?

  26. #26
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Using .Offset() how you are using it is incorrect. The reason my initial code included a .Offset(1) was to skip over the header by offsetting 1 row.

    At this point I really have no idea what you are trying to do. I understand that the code is probably challenging to comprehend and you are trying to just smash your way through but unfortunately, you are not going to be able to do that.

    What is this default schedule you previously referenced and where do you want it to go. Give some specific cell references.

    Note: If you are wanting to learn I could probably write code in an easier to understand, but less efficient, manner. If this is the case let me know and I will attempt it if I have time.
    Last edited by stnkynts; 12-17-2014 at 08:17 PM.

  27. #27
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Thanks for the help. Let me try to be more clear and explain referencing the attached file: demo4.xlsm

    You've written a code that changes the values in defined columns "CB", "EF", "GJ", "IN", "KR", "MV", "X", "OZ" based on the "Y" or "N" input in columns L:R. This works great. What I am trying to add is that if (for example) the cell L7 is "Y", CB7 becomes "WORK" and CC7 = Q7, CD7 = R7, CE7 = S7, CF7 = T7, CG7 = U7 where columns Q:U is the default schedule and CC:CG is the specific schedule for that day.

    Please let me know if this is unclear. I like the efficiency of your code and would like to keep it that way.

    Thanks!

  28. #28
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Try this:

    Please Login or Register  to view this content.
    EDIT: The above code has been modified for improved performance
    Last edited by stnkynts; 12-19-2014 at 10:28 AM.

  29. #29
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Thanks man this works great! There is one last change I'd like to make if possible. Under the
    Please Login or Register  to view this content.
    tree, how would I make the cells in the range
    Please Login or Register  to view this content.
    (just like what what was listed under
    Please Login or Register  to view this content.
    ) just equal "" (blank)?

  30. #30
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    I tried

    Please Login or Register  to view this content.
    but it only clears the first column of the range selected as "N"

  31. #31
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Change value in column based on value in other column

    Instead of rCell.ClearContents try this:

    Please Login or Register  to view this content.
    Last edited by stnkynts; 12-31-2014 at 11:01 AM.

  32. #32
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change value in column based on value in other column

    Thank you sir! You are ******* awesome.

+ 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] Populate a Column Based on the Change in data of Another Column
    By bridgeport in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-24-2014, 11:37 AM
  2. Change colour in column C based on Column B - future dates
    By kfwiss in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-22-2013, 05:47 AM
  3. Replies: 4
    Last Post: 09-05-2012, 01:50 PM
  4. Replies: 4
    Last Post: 07-30-2012, 04:21 PM
  5. Trigger column value changes in worksheet WS2 based on value change in WS1 column
    By sunny89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2010, 12:04 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