+ Reply to Thread
Results 1 to 8 of 8

Clearing cells based upon changed cells

  1. #1
    Registered User
    Join Date
    10-29-2013
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Clearing cells based upon changed cells

    Good day all.

    I'm trying to come up with some VBA code that will do the following:

    1) If the value of cell Y13 changes, clear the contents of cells N13 and AC13
    2) If the value of cell Y14 changes, clear the contents of cells N14 and AC14
    3) Etc. all the way up to cels Y34, N34, and AC34

    I'm sure there is a relatively simple and elegant way to do this that does not involve writing a macro for each cell...which is what I started to do as follows:

    Please Login or Register  to view this content.
    Any help would be appreciated!

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Clearing cells based upon changed cells

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

  3. #3
    Registered User
    Join Date
    10-29-2013
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Clearing cells based upon changed cells

    Thanks StephenR

    That appears to correctly clear column "N", but it isn't working for column AC. I am getting "Run-time error '1004': Cannot change part of a merged cell."

    I did not mention... my cells Y13 through Y34 are merged across through column AB. (For example, Y13 is merged with Z13, AA13, and AB13).

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Clearing cells based upon changed cells

    There's a lesson - don't use merged cells. In any case do you mean AC is merged?

  5. #5
    Registered User
    Join Date
    10-29-2013
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Clearing cells based upon changed cells

    Unfortunately, in order to make this spreadsheet presentable, merged cells are a necessary evil. (The cells contain data validation/drop down pick lists, and I need the cell wide enough to be able to view what the user is picking.)

    AC is not merged..Y is merged with Z, AA, and AB.

    I've uploaded the spreadsheet so you can see what is going on. The sheet that I want this to work on is "LINE CLASS" The intent is that when the information in the "Material" column (merged cells Y:AB) is changed, the values in the "Ej" and "Form" column will clear, and force the user to reselect them.

    Try not to laugh too hard at the mess that this spreadsheet is...I'm taking something that was developed by others and trying to improve it and I'm only halfway there.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Clearing cells based upon changed cells

    You'd be better off adjusting the column width. Anyway, good luck with that!

    Change the 4 in the second offset to 1.

  7. #7
    Registered User
    Join Date
    10-29-2013
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Clearing cells based upon changed cells

    Excellent, worked like a charm!

  8. #8
    Registered User
    Join Date
    10-29-2013
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Clearing cells based upon changed cells

    StephenR, I'm taking your advice and reorganizing the sheet to get rid of merged cells within my formula areas...the solution above will provide an error if a user selects multiple (merged) cells and tries to delete them, or attempts to copy a value to multiple merged cells. I considered adding a bit of code to prevent users from selecting more than one cell, but decided that impaired the functionality of the sheet too much.

    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. Clearing option buttons based a on cells value where the cells value is not typed in.
    By Tanner2004 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2013, 03:56 PM
  2. [SOLVED] Clearing the contents of certain cells after another cell has been changed.
    By ndrobinson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-13-2012, 11:14 AM
  3. Clearing cells based on value
    By Pasha81 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2010, 09:59 AM
  4. Clearing cells and deleting rows based on condition
    By vijay2482 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2010, 10:08 AM
  5. Clearing Contents in 2 cells, based on the value of 3 cells
    By hriggs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2009, 06:39 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