Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Cells in VB

Status
Not open for further replies.

wrightlefty

Technical User
Feb 19, 2004
17
US
Cell "E12" is populated by validation.

All other validated cells look to "E12" for information.

If the value in cell "E12" is changed, all other cells should have any value in them cleared and be ready for a new value to be selected.

The code I tried to use does not work...

Private Sub worksheets(Custom_Motor)
If Click.cells.["E12"] Then Range("e14,e16,e18,e20,e22").ClearContents
End Sub

Thanks for all your help.
 
You need to put the code in the worksheet that you're using. From the VBA editor right click on the sheet you want to monitor and choose "View Code". Then, from the drop-down menu, select "Worksheet" and "SelectionChange". Swap out the test case with:
Code:
If Target = ActiveSheet.Range("E12") Then
   ActiveSheet.Range("e14,e16,e18,e20,e22").ClearContents
End If

That should be what you're looking for.

----------------------------------------
If you are reading this, then you have read too far... :p
 
Thanks logius!

This did do what I asked; however, after seeing how the spreadsheet now operates I have a different question.

As mentioned before cell "E12" in populated via validation. Is it possible for the dependant cells to clear only if the value in "E12" changes, rather than just if someone clicks in it?

Thanks again.
 
Thanks Robert, it worked perfectly! Thanks again to both of you, very helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top