+ Reply to Thread
Results 1 to 7 of 7

Need help creating a macro to clear 2 non-consecutive cells in a range

  1. #1
    Registered User
    Join Date
    07-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    37

    Need help creating a macro to clear 2 non-consecutive cells in a range

    Hello everyone. I haven't been on the site in a while, but I'm back with a problem that should be simple, but has stumped me.
    I'm trying to create a macro that checks to see if cells b12:c12 are empty and if they are clears the cell contents of k12.
    I also want a separate macro that checks to see if cell g36 is empty and if it is then clears the cell contents of k36.
    Below is the macro that I have that accomplishes the first part, but I can't figure out how to include a macro that solves the second part of my problem.

    Thanks in advance for any assistance that anyone can provide.
    ***************************************************
    Please Login or Register  to view this content.
    Last edited by gophil1; 05-07-2019 at 08:12 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,906

    Re: Need help creating a macro to clear 2 non-consecutive cells in a range

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. 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, and it also maintains VBA formatting.

    Click on Edit to open your post, 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

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    37

    Re: Need help creating a macro to clear 2 non-consecutive cells in a range

    Thank you, sorry for the error; I've corrected my post. I thought that I was forgetting something.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    As a beginner starter :

    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range)
            
    Application.EnableEvents False
        Select 
    Case Target.Address
               
    Case "$B$12""$C$12"
                    
    If Join(Application.Index([B12:C12].Value20), "") = "" Then [K12].ClearContents
               
    Case "$G$36"
                    
    If Target.Value2 "" Then [K36].ClearContents
        End Select
            Application
    .EnableEvents True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    07-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    37

    Re: Hi ! Try this !

    I had to make the below modification in order to get the clear contents for cell K12 to work, but your solution works great. Thanks so much.
    *****************
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Need help creating a macro to clear 2 non-consecutive cells in a range


    As you did not explain there were merged cells …

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,906

    Re: Need help creating a macro to clear 2 non-consecutive cells in a range

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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] Macro to clear cells in range & move up if certain cells meet criteria
    By samder68 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2016, 10:52 PM
  2. [SOLVED] Macro to Clear contents in a range of cells when Date change.
    By aneshdas in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-08-2014, 01:53 AM
  3. Replies: 1
    Last Post: 06-21-2013, 04:05 AM
  4. [SOLVED] Macro needed to clear cells in range based on value of cells in another range
    By msmith7113 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2013, 12:32 AM
  5. [SOLVED] Clear contents for consecutive duplicates in selected range
    By AM0305 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-30-2013, 09:04 PM
  6. Replies: 3
    Last Post: 09-18-2012, 11:32 AM
  7. Replies: 2
    Last Post: 06-21-2011, 12:54 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