+ Reply to Thread
Results 1 to 7 of 7

Clearing content in cell when value in other cells changes

  1. #1
    Registered User
    Join Date
    07-10-2018
    Location
    Manchester, England
    MS-Off Ver
    Office 2010
    Posts
    8

    Clearing content in cell when value in other cells changes

    Hi

    I've just joined the Forum and this is my first post.

    I found this code online and pasted into General / Declarations. It is designed to clear the contents of C4 and C12 whenever the value in C2 changes

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C2")) Is Nothing Then
    Range("C4").ClearContents
    Range("C12").ClearContents
    End If
    End Sub

    This works exactly as I want it too, but now I want to add another condition. That is to clear the contents of C12 if C4 changes i.e. I want both these to work in the same sheet.

    Required behaviour:
    if C2 changes, clear both C4 and C12
    if C4 changes, clear C12 only

    I'm not a VBA programmer and really not sure where to start. Any tips would be much appreciated!

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    05-12-2018
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    266

    Re: Clearing content in cell when value in other cells changes

    Please Login or Register  to view this content.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Clearing content in cell when value in other cells changes

    Try:

    Please Login or Register  to view this content.
    Last edited by xladept; 07-10-2018 at 01:18 PM. Reason: Double Dip
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Clearing content in cell when value in other cells changes

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Registered User
    Join Date
    07-10-2018
    Location
    Manchester, England
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Clearing content in cell when value in other cells changes

    Hi

    Many thanks for your help..

    Unfortunately when I try this, I get the compile error 'End if without block if'

    Any ideas?

    Thanks

  6. #6
    Registered User
    Join Date
    07-10-2018
    Location
    Manchester, England
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Clearing content in cell when value in other cells changes

    Hi

    Thanks so much for this. It has worked a treat and does exactly what I want it to!

    Cheers
    Mike

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Clearing content in cell when value in other cells changes

    Who are you thanking? If it's me then you're welcome!

+ 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: 07-17-2015, 03:30 AM
  2. [SOLVED] Clearing cell content based on expired date
    By Loadtoad in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-04-2014, 03:56 PM
  3. Cell content clearing when using Save As macro
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2013, 10:07 AM
  4. clearing content from blank cells
    By cotw in forum Excel General
    Replies: 6
    Last Post: 08-11-2012, 01:44 PM
  5. [SOLVED] Clearing cells content when opening up an Excel workbook
    By grumpyguppy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2012, 10:58 PM
  6. clearing cell content on MAC?
    By themachine in forum Excel General
    Replies: 4
    Last Post: 07-22-2010, 08:39 AM
  7. clearing cell content in a macro
    By dziw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2007, 12:02 AM

Tags for this Thread

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