VBA - Clear contents of a row, dependent on a cell's value

vvilko

New Member
Joined
Jul 5, 2017
Messages
10
Hi Guys.

I'm looking at creating a VBA code to look for the value in 'J' Column to change to "Yes". When it changes, I'd like it to clear all values to the Right (K to AH) in that particular row (leaving formulas in "Y", "AA" and "AC").
it would also have to check every row in the workbook.
I've been trying different things for about 4 hours now, and I've only managed to get it to clear a single row...

I hope you can help me out.

1629194516187.png

*Sorry, I tried to use XL2BB but I think my IT have disabled Microsoft Add-Ins.*

thanks in advance.
vvilko
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi, @vvilko
Try this:
This is an Event Procedure, you need to put it in the code module of the sheet in question (say sheet1). This is how:
Copy the code > open sheet1 > right click sheet1 tab > select View Code > paste the code.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo skip:
If Target.Cells.CountLarge > 1 Then Exit Sub
    If Not Intersect(Target, Range("J:J")) Is Nothing Then
        If Target.Value = "Yes" Then
        Dim i As Long
        Application.EnableEvents = False
            i = Target.Row
            Range("K" & i & ":AH" & i).SpecialCells(xlCellTypeConstants).ClearContents
        Application.EnableEvents = True
        End If
    End If

Exit Sub
skip:
Application.EnableEvents = True
MsgBox "Error number " & Err.Number & " : " & Err.Description
End Sub
 
Upvote 0
Solution
That works amazingly! Thank you so much for the help. I'm slowly learning, but some things go over my head.
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,811
Members
449,339
Latest member
Cap N

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