Clear contents of cell range based on cell value

mickyflash

Board Regular
Joined
Jan 29, 2009
Messages
77
Hello, I wonder if anyone could help me. I am looking for a code/formula which I am pretty sure can be done but I do not know VBA well enough to adapt anything I found on this site.

I would like to delete the values in cell C2:AF2 IF C2 = sheet2!a2

only I would like the range to include all rows upto row 60

so if C59 - SHEET!A2 then delete the values in C59:AF59

I apologies in advance for my lack of knowledge and I hope I am explaining myself well.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
No help yet.. but I have looked into this a bit more and this is what I have come up with:

Sub clear_stuff()
If Sheets("Sheet1").Range("c2").Value = "Yes" Then
Sheets("Sheet1").Range("d2:ag2").ClearContents
End If
End Sub

This works for one cell ("C2")
is there an easy way to adapt this to work for all cells is C:C?
 
Last edited:
Upvote 0
Try

Code:
Sub clear_stuff()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        If .Range("C" & i).Value = "Yes" Then
            .Range("D" & i & ":AG" & i).ClearContents
        End If
    Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,245
Members
448,555
Latest member
RobertJones1986

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