Clear range of cell content based on another cell value

batkinsp

New Member
Joined
Apr 21, 2009
Messages
1
This is my first post.
I have spent the better part of the day trying to adapt some of the code found here.
What I want to accomplish is to clear a range of cells if the value of another cell does not equal a specific value.
I have been able to get a macro to work but it is manual.
I need the cells to be cleared automatically

I have a cell C7 that could be any value from 1 to 30.
Cell D7="30"
If C7 <> D7 then Range J7:J29 = "" and Range H9:H16 = ""

Here is the code I have gotten to work manually
Option Explicit
Sub testme()
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim rng4 As Range
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Set rng1 = Range("C7")
Set rng2 = Range("D7")
Set rng3 = Range("J7:J29")
Set rng4 = Range("H9:H16")
If LCase(rng1.Value) <> (rng2.Value) Then
rng3.clearcontents
rng4.clearcontents
End If
End Sub

I have attempted to adapt this code to a change event unsuccesfully.

Any assistance would be greatly appreciated.
------
Bill
 
Put this in your Sheet vba code


Private Sub Worksheet_Change(ByVal Target As Range)

testme


End Sub

you could put an "if" statement in there on the range it gets on the change.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top