Conditional delete

T

tom

Hi,

A B C
D E F
G H I

are a block of cells. Cell C is the active cell (cursor position). If cell D
contains the word "Group N" where N can be a number from 1 to 4, I want to
delete the content of cells D, E, F, G, H and I. If not, to continue on with
the next line of code.
Any help is much appreciated.

TIA
Tom
 
J

Jarek Kujawa

select your C, F, I cells (or further down) and try:

Sub cus()

For Each cell In Selection
For i = 1 To 4
If cell.Offset(1, -2) = "Group " & i Then
Range(cell.Offset(1, -2), cell.Offset(2, 0)).ClearContents
Exit For
End If
Next i
Next cell

End Sub

pls click YES if it helped
 
T

tom

Those codes work perfectly. Thank you, Jarek.

Regards,
Tom

select your C, F, I cells (or further down) and try:

Sub cus()

For Each cell In Selection
For i = 1 To 4
If cell.Offset(1, -2) = "Group " & i Then
Range(cell.Offset(1, -2), cell.Offset(2, 0)).ClearContents
Exit For
End If
Next i
Next cell

End Sub

pls click YES if it helped
 

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

Top