Closed Thread
Results 1 to 14 of 14

Thread: Macro to clear cells

  1. #1
    Registered User
    Join Date
    02-24-2011
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Macro to clear cells

    Hi, I'm having trouble writing a macro to clear cells.

    I want to clear the contents of a column when I switch between two values in a drop-down data validation menu. I have tried using the macro recorder but have had no success.

    I'm new to macros!

    Cheers

    Joe
    Last edited by joe87; 02-28-2011 at 08:26 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Macro to clear cells

    Columns(3).clear
    or

    Range("H:H").clear
    If you need more help you are going to have to supply more meaningful details.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Macro to clear cells

    Supply more details please.

  4. #4
    Registered User
    Join Date
    02-24-2011
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to clear cells

    Does this help?

    I can attach the whole spreadsheet but its a little incomprehensible!
    Attached Images Attached Images

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Macro to clear cells

    Not really.

    Take a step back. Imagine you know nothing of the workbook or it's purpose or what the guy posting is doing or wants.

    Now read your post and see if you can understand the problem being asked.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    02-24-2011
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to clear cells

    OK...

    In the worksheet "Interface", in cell D12, I have a drop down menu with 2 options - "Imperial" and "Metric". Whenever I change between the two options I want the cells in the range E16:E40 to be cleared.

    I have no idea how to go about this except that it might involve a Change Event triggering a Macro?

    Thanks for your help guys!

  7. #7
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Macro to clear cells

    What is the drop down menu? Is it a cell with Data validation?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Macro to clear cells

    right click sheet tab and pick View Code.
    Paste the following

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Not Intersect(Range("D12"), Target) Is Nothing Then
            Application.EnableEvents = False
            Range("E16:E40").Clear
            Application.EnableEvents = True
        End If
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  9. #9
    Registered User
    Join Date
    02-24-2011
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to clear cells

    Roy, It was a data validation cell.

    Andy, that worked ok, but it has deleted the drop down menu options. Is there a way to just clear the contents of the cell without deleting the data validation facility?

    Cheers

    Joe

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Macro to clear cells

            Range("E16:E40").ClearContents
    Cheers
    Andy
    www.andypope.info

  11. #11
    Registered User
    Join Date
    02-24-2011
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to clear cells

    Thank you so much! Fantastic

  12. #12
    Registered User
    Join Date
    04-23-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to clear cells

    Hi,

    Sorry for hijacking the thread.

    I also have a cells C30 : C79 which have data validataion drop down values. On the basis of what being the input in the respective cells C30:C79 there is a dependent drop down values in the D30:D79. Again there is a drop down(YES|NO) in cells E30:E79.

    Now my query is if i change the input in any of the cells in C30:C79 then respective cells under D30:D79 & E30:E79 should clear the contents so that the appropriate values can be selcted from the drop downs.

    I have been trying to use below macro code however it doesnt solve the pupose. If I replace C30:C79 by C30, D30:D79 by D30 and E30:E79 by E30 then it works like a charm for the cells C30 but when i tried to generalize this for whole range it doesnt yield the result.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, ActiveSheet.Range("C30:C79")) Is Nothing Then Exit Sub
    ActiveSheet.Range("D30:D79").Value = ""
    ActiveSheet.Range("E30:E79").Value = ""
    End Sub

    Please let me know your inputs.

    Thanks,
    Aks

  13. #13
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007,2010
    Posts
    6,843

    Re: Macro to clear cells

    Quote Originally Posted by aks_cool View Post
    Hi,

    Sorry for hijacking the thread.
    Then don't, start your own thread.

  14. #14
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Macro to clear cells

    And use Code Tags when you do
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0