I have a table ranging from ("C22:Q26"), where cell ("R22"), ("R23"), ("R24") up to ("R26") are the cells to be selected in a row, to clear contents.
I want to clear contents of a range("C22:Q22"), when cell ("R22") is selected.
Similarly clear contents of a range("C23:Q23"), when cell ("R23") is selected, and so on up to range("C26:Q26") when cell ("R26") is selected.
I wrote this, placed in sheet code.
Sub clearcontents()
If Range("r22").Selected Then
Range("R22").Offset(, -15).Resize(, 15).Select
Range("R22").Offset(, -15).Resize(, 15).clearcontents
ElseIf Range("r23").Selected Then
Range("R23").Offset(, -15).Resize(, 15).Select
Range("R23").Offset(, -15).Resize(, 15).clearcontents
ElseIf Range("r24").Selected Then
Range("R24").Offset(, -15).Resize(, 15).Select
Range("R24").Offset(, -15).Resize(, 15).clearcontents
ElseIf Range("r25").Selected Then
Range("R25").Offset(, -15).Resize(, 15).Select
Range("R25").Offset(, -15).Resize(, 15).clearcontents
ElseIf Range("r26").Selected Then
Range("R26").Offset(, -15).Resize(, 15).Select
Range("R26").Offset(, -15).Resize(, 15).clearcontents
End If
End Sub
Worksheet.SelectionChange
event.