VBA to clear contents of a cell

MrRosco

New Member
Joined
May 12, 2016
Messages
47
Hi All,

I would like to know if it i possible to clear the contents of a cell once another has a value (or a LEN value greater than zero)

in my worksheet if cell AJ6 has a value then i would like AI6 to be deleted. i need this to happen for each row as at this moment i don't know how many entries i will have.

Thanks in advance for your help.

Ross
 
So, are manual entries being made to the cells in columns AM and AN?
If so, then entries in to these cells would be the thing to trigger the VBA code to run.
Would you agree?
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
AM and AN both contain formulas, however AK is a manual entry which triggers the formulas in AM/AN. would this work?
 
Upvote 0
Yes, just change the code I posted to activate when a change is made to column AK, i.e.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   See if only one change, and change is to entry in column AK
    If Target.Count = 1 And Target.Column = 37 Then
'       If entry in column AJ is not blank, clear entry in column AI of same row
        If Target.Offset(0,-1) <> "" Then Target.Offset(0, -2).ClearContents
    End If
        
End Sub
Note how everything is relative to column AK (column 37).
AJ is one column to the left of AK, hence the Offset(0,-1)
AI is two columns to the left of AJ, hence Offset(0,-2)
 
Upvote 0

Forum statistics

Threads
1,217,086
Messages
6,134,479
Members
449,874
Latest member
Cl2130

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