View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ck ck is offline
external usenet poster
 
Posts: 52
Default Clear Cell Contents based on Criteria of another cell

Your code worked, but the macro kept running so I had to break out of it.
Here's a more detailed explanation...
The only time I want the cells cleared is when someone enters the criteria
'n' and then I want the cells that are adjacent to be cleared immediately.
I'm creating a template and the customers will go down a list and respond "y
or n" to that list. If it is 'y', the cells adjacent will be highlighted in
yellow (I'm using conditional formatting for this); if it is 'n' the adaject
cell to the right must be cleared of content immediately.
Thanks for your help.
--
CK


"Jacob Skaria" wrote:

Try the below code; but are sure you want this code within the
WorkSheet_Change event or as a separate macro..........


Dim lngRow As Long
Dim lngLastRow As Long

lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = 2 To lngLastRow
If LCase(Range("B" & lngRow)) = "n" Then
Range("C" & lngRow & ":D" & lngRow).ClearContents
End If
Next

--
If this post helps click Yes
---------------
Jacob Skaria


"CK" wrote:

Hi,
Column B will have the criteria (y or n). If n is entered, the data in the
two cells adjacent and to the right of the current cell must have the
contents cleared. I can accomplish this for one row in Column B but I need
to have this occur for the other rows. This is what I have so far..

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng1 As Range
Dim rng2 As Range

Set rng1 = Range("b2")
Set rng2 = Range("c2:d2")

If LCase(rng1.Value) = "n" Then
rng2.clearcontents

End If
End Sub

Any help is appreciated. This is my first shot at VBA.

--
CK