Clear Contents Help

M

michael

I'd like some help with clearing contents using vba.

If cell D18="Combo" (selected from a Data Validation List), clear the
contents of cells D19, D20, D21, D22 & D26.

If cell D18="One" (selected from a Data Validation List), clear the
contents of cells D23, D24, D26, D27, D28 & D29.

Much thanks in advance!

-Mike
 
R

Ron de Bruin

You can use the change event to do this

Place the code in the Sheet module

Right click on a sheet tab and choose view code
Paste the code there
Alt-Q to go back to Excel

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("D18"), Target) Is Nothing Then
If Target.Value = "Combo" Then Range("D19, D20, D21, D22:D26").ClearContents
If Target.Value = "One" Then Range("D23, D24, D26, D27, D28:D29").ClearContents
End If
End Sub
 
D

Die_Another_Day

Sub ClearData
If Range("D18").Value = "Combo" then
Range("D19:D22").ClearContents
Range("D26").ClearContents
elseif Range("D18").value = "One" then
Range("D23:D24").ClearContents
Range("D26:D29").ClearContents
end if
End Sub

HTH

Die_Another_Day
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Run macro on selected sheets 10
VBA Help 3
Clear contents on specified ranges 3
Save as 13
Is there a better way? 10
Formulas 2
Double-Click to Change Interoir Color 4
Function =IF statment limits 3

Top