+ Reply to Thread
Results 1 to 4 of 4

VBA MAcro to clear contents of specific cells if a specific cell contains text

  1. #1
    Registered User
    Join Date
    08-21-2015
    Location
    Sunshine Coast, Australia
    MS-Off Ver
    2013
    Posts
    2

    Exclamation VBA MAcro to clear contents of specific cells if a specific cell contains text

    I am trying to use a macro to do the following
    If cell D279 contains any text then Clear contents of cells D276 & D277 - All cells are using data validation lists if an item is selected in Cell D279 than the items in D276 & D277 are no longer required.
    I have tried the following code with Any & specific Text but it dosent seem to work

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("D279")) Is Nothing Then
    If UCase(Range("D279")) = "Upgrade - To Ilve CJK90CSVI 90cm Dual fuel Upright Cooker" Then
    Application.EnableEvents = False
    Range("D276").ClearContents
    Range("D277").ClearContents
    Application.EnableEvents = True
    End If
    End If
    End Sub

    Appreciate any help
    cheers

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA MAcro to clear contents of specific cells if a specific cell contains text

    Hi muzzareilly:

    First of all please review the forum rules, not only, but especially #3 about using code tags.

    That said, in this line:

    Please Login or Register  to view this content.
    UCase is a function that converts D279 to caps, so the If statement will NEVER return true, thus the code does nothing.

    Change it to:

    Please Login or Register  to view this content.
    and see if it starts to work. Or if ANY text in D279 should trigger it then:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    08-21-2015
    Location
    Sunshine Coast, Australia
    MS-Off Ver
    2013
    Posts
    2

    Re: VBA MAcro to clear contents of specific cells if a specific cell contains text

    Thanks Arkadi that seems to have worked
    Sorry about the code tags my first post.
    cheers

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA MAcro to clear contents of specific cells if a specific cell contains text

    Glad I could help out, no worries about code tags, you are new and have to learn so I was just pointing it out
    If the issue is resolved, please remember to mark the thread as solved (at the top right, under Thread Tools, you can select to mark as solved).

+ 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] Clear cells that do not contain specific text which may be at the beginning or end of cell
    By Sianee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2015, 02:53 PM
  2. [SOLVED] code to clear all contents in columns with specific text in row 2
    By xcelnovice101 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-30-2014, 08:58 AM
  3. [SOLVED] Clear contents in specific cell and the cells in the next 2 columns to the right
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2014, 01:25 AM
  4. [SOLVED] Clear contents of specific cells on the same row if a specific cell on that row is empty
    By djfscouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2014, 01:48 PM
  5. [SOLVED] VBA Macro To Clear Cell When Specific Text Is Entered
    By paulm99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2014, 06:52 PM
  6. Macro to clear only the contents of the cells which have a specific font colour
    By Stellakyp in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-05-2013, 11:01 AM
  7. Clear contents of cells that do not contain specific text, sort cells that do
    By feckless.lout in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 01:41 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