Simple VBA code required to clear cell contents

paulfisher

New Member
Joined
Jun 19, 2014
Messages
2
I have a very large spreadsheet that requires processing soon.
The records in Column AD are drop down dependent on the answers to the same row in column AE.

I am only a VBA beginner and I have tried, but not yet succeeded, to write/find some VBA that will clear the related row entry in column AD if column AE is altered.

I have tried a code that works but only on a single row - say if AE2 is altered it clears AD2 and I did for a while have some code that if you alter any row in AE would clear EVERY row in AD however this is not quite what I want.

If I for example alter AE1965 I would like AD1965 cleared but not affect AD1:AD1964 or AD1966:AD2500.

Please help me!

Paul
 
Welcome to MrExcel.

Try this in the module for the worksheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    If Application.Intersect(Target, Columns("AE")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    On Error GoTo Cleanup
    For Each Cell In Target.Cells
        If Cell.Column = Range("AE1").Column Then
            Cell.Offset(0, -1).ClearContents
        End If
    Next Cell
Cleanup:
    Application.EnableEvents = True
End Sub
 
Upvote 0
A working response within 10 minutes - brilliant, thanks.
I guess need to refer to the off-set if I wish to alter the column order...

Many thanks!
 
Upvote 0

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