+ Reply to Thread
Results 1 to 3 of 3

VBA .ClearContents code

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    shelton, wa
    MS-Off Ver
    Office 365
    Posts
    24

    VBA .ClearContents code

    I am trying to figure out how to write a code in VBA that would Clear the Contents of a cell. I have two sheets, sheet1 & sheet2. On sheet1 cell A1, there is a drop down box with selections of Colors, Numbers, Letters. Cell A2 has another dropdown box that is populated depending on the option you selected in A1, so if you choose Letters in A1 then the dropdown list only shows you A-Z for possible selections. If A1 was Numbers, you would get to choose numbers 1-100 on the drop down list of A2, etc...

    The problem is if I already have A1 and A2 selected and if I want to make a new selection in A1, I drop down the list in A1 make a choice and A2 does not auto blank. So if I was to stop here I have an incorrect item showing in A2 until I click on the drop down box. So if I had my selection of Colors and B1 is Pink, and I went back up to A1 and now picked Numbers, my choice of Pink is still showing.


    So I put a new tab, made a formula in Sheet2 cell A2 that said if Sheet1 A2 was a true selection and fell within the range of Colors then = 1 if not = 0, etc... so now if A2 really does not match up to the A1 selection then I get a 0.

    Now I am trying to figure out how to write a code that says if Sheet2 cell A2 = 0 clearcontent of Sheet1 cell A2. This would be a simple building block for me to learn and build on for this. Thank you. Oh, I did try to record a marco, but was not able to assign it to the drop down box.

    Right now I am stuck on this


    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    07-08-2012
    Location
    Melbourne Australia
    MS-Off Ver
    Excel 2003
    Posts
    79

    Re: VBA .ClearContents code

    to clear your dependant data validation list in "A2" maybe use

    Please Login or Register  to view this content.
    if your wanting to expand it to clear "B2" as well maybe add this addtional line before "Next cell"

    Please Login or Register  to view this content.
    Last edited by gwsampso; 12-10-2012 at 08:57 PM.

  3. #3
    Registered User
    Join Date
    12-28-2009
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: VBA .ClearContents code

    Another approach to clear A2 as you change A1 value.
    Install the code below into sheet1 module.


    Please Login or Register  to view this content.
    Osvaldo

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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