+ Reply to Thread
Results 1 to 5 of 5

excel clear cell contents if another cell changes

  1. #1
    Registered User
    Join Date
    01-14-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    excel clear cell contents if another cell changes

    Hi there,

    I need an expert's help please!

    I have typed the following code into my excel spreadsheet:

    Use Application.EventHandling = False/True

    Please Login or Register  to view this content.
    However, I also need this to work for cell (F13) changing cells F16 and F20.

    I tried typing:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Please Login or Register  to view this content.
    End If
    End Sub

    But it came up with an error "Block if without End If. I am a complete novice at coding and don't understand what this means - can anyone help please?

    Thanks
    Last edited by Cindi Novell; 01-31-2019 at 03:52 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,941

    Re: excel clear cell contents if another cell changes

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    Please Login or Register  to view this content.
    You should also switch event handling before making changes and switch it on again afterwards. Use Application.EventHandling = False/True
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-14-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: excel clear cell contents if another cell changes

    I'm not sure if what I have done is correct, but I have made the changes you asked for. Can you please tell me where I am going wrong? Thanks

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: excel clear cell contents if another cell changes

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,941

    Re: excel clear cell contents if another cell changes

    My apologies ... I didn't explain clearly enough, and didn't use the specific method correctly. Late at night and untested

    This is what it should have looked like ... the End If was missing and I've added the event handling correctly.

    Please Login or Register  to view this content.
    bakerman2's solution is neater

+ 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] Needing VBA code to clear contents of cell when the contents of another cell is cleared
    By jeh0714 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-15-2016, 03:49 PM
  2. Clear merged cell contents in comand button(clear all)
    By mohan_984 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-25-2015, 10:39 AM
  3. VBA to clear contents of the cell in a column of data in a cell starts with specific word.
    By winmaxservices1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2015, 08:25 AM
  4. Clear contents in one cell when contents of another cell are deleted
    By rlbush2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2012, 10:29 PM
  5. [SOLVED] Clear contents of last used cell in a range and those previous to it (excel 2003)
    By chris_norton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2012, 02:06 PM
  6. Macro that will clear contents of cell based on format of text in adjacent cell
    By judasdac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2012, 01:56 AM
  7. [SOLVED] [SOLVED] Excel should let me clear cell contents without clearing formulas
    By BJM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-19-2005, 01:00 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