+ Reply to Thread
Results 1 to 5 of 5

Changing value of cells based on adjacent cell value - super messy code alert

  1. #1
    Registered User
    Join Date
    09-20-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    3

    Changing value of cells based on adjacent cell value - super messy code alert

    Hey folks,

    I'm new to this forum so apologies in advance for anything I don't quite get right. I've read the forum rules but being autistic I'm not 100% on the social etiquette yet so I'll do my best.


    My question is as such.


    I have a spreadsheet which shows products (watches/jewellery) and the amount purchased but I need to discard certain products (for instance jewellery sets, loyalty points and watch warranties). I've done this by creating some VBA code that I mashed together (from code I found online) which looks for certain text in one column and then changes the number value of the adjacent column to 0.

    The issue is that my code looks really horrible and super messy and I've effectively done a whole bunch of "nested ifs" (I think that's what they're called) for each parameter and I would like it to look slightly less messy.


    I also have the issue that watch warranties are shown as "101" but one of our watches is shown as "5101" which means that I then have to go back and change all the values for "5101" back to their original value instead of "0".


    I'll post the code I have so far and if anyone has any ideas to point me in the right direction I'd be super grateful!



    Please Login or Register  to view this content.


    Thanks in advance folks but if you need any more information then please let me know. I did want to copy some of the spreadsheet into here so you could see it visually but I'm not entirely sure how to do that yet. Haha.


    Kind Regards

    Fiona

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Changing value of cells based on adjacent cell value - super messy code alert

    You posted you first query perfectly, Fiona. You should teach others how to do it.

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-20-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    3

    Re: Changing value of cells based on adjacent cell value - super messy code alert

    Oh thanks! I'll keep going as I am then!


    The code is awesome thanks! It works for the most part, except that now cells with 101 in them aren't picked up by the code and so their values don't change. This helps me with the 5101 issue but I still need all the cells with 101 in them to change to 0. Is there any way of doing like "do the thing if the cell has the exact text 101 in it" and "do not do the thing if the cells has teh exact text 5101 in it"?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Changing value of cells based on adjacent cell value - super messy code alert

    Change this...
    "*[!5]101*"

    To this...
    "101"

  5. #5
    Registered User
    Join Date
    09-20-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    3

    Re: Changing value of cells based on adjacent cell value - super messy code alert

    Fantastic! That works like a charm! Thanks so much!

    Kind Regards

+ 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. Alert while saving the file if there are two adjacent cells with specific values
    By buhaj47 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2018, 09:17 AM
  2. Replies: 3
    Last Post: 10-21-2015, 03:51 PM
  3. code to copy content to adjacent cells based on a cell value
    By anbarasi_r in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-28-2015, 12:42 PM
  4. Code How to show alert messages with the IF condition based on other cell value
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2013, 09:51 PM
  5. Replies: 5
    Last Post: 08-10-2012, 04:32 PM
  6. Code to pull cells into a new workbook based on content of adjacent cells
    By Greed in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2012, 10:05 AM
  7. changing a cell depending on the fill colour of adjacent cells
    By debbiec in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-21-2009, 06:11 AM

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