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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
The question is, when do you want this to run?
You could call the macro/VBA code to run manually, or you could have it run automatically on some event happening (like when cell AJ6 is manually updated)?
 
Upvote 0
If you want it to happen upon the entry of something in column AJ, this code should do that.
Just right-click on the sheet tab name, select "View Code", and paste this code in the resulting VB Editor window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   See if only one change, and change is to entry in column AJ
    If Target.Count = 1 And Target.Column = 36 Then
'       If entry in column AJ is not blank, clear entry in column AI of same row
        If Target <> "" Then Target.Offset(0, -1).ClearContents
    End If
        
End Sub
 
Upvote 0
If you want it to happen upon the entry of something in column AJ, this code should do that.
Just right-click on the sheet tab name, select "View Code", and paste this code in the resulting VB Editor window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   See if only one change, and change is to entry in column AJ
    If Target.Count = 1 And Target.Column = 36 Then
'       If entry in column AJ is not blank, clear entry in column AI of same row
        If Target <> "" Then Target.Offset(0, -1).ClearContents
    End If
        
End Sub



Hi Joe,

Thanks for getting back to me. i have tried this in my workbook and cell AI7 does not get deleted.

could this be due to the cell AJ has a formula?

Thanks
Ross

Thanks
Ross
 
Upvote 0
Yes, that will only work if the values in column AJ are being manually updated.
So, that takes me back to the question I asked in my first reply:
The question is, when do you want this to run?
You could call the macro/VBA code to run manually, or you could have it run automatically on some event happening (like when cell AJ6 is manually updated)?
 
Upvote 0
Hi,

Apologies for that, cell AJ has a formula as its calculating actual sales and promotional cost. Cell AI is also calculated forecast.

is this something you can help with?

Ross
 
Upvote 0
is this something you can help with?
Yes, but I need you to answer my question.

I am not asking what is in each cell, rather I am asking when and how you want this to run?
Is there some "action" that you want to automatically trigger this process?
Or, do you just want a macro that you can call and run yourself whenever you want (if so, what range should it run on? all of column AI, or just certain rows)?
 
Upvote 0
I would like it to be automatic, the trigger point will be when Cell AJ has a value (which if formulated) AI will be deleted.

the range will be all of AI & AJ,

anything else please let me know

Ross
 
Upvote 0
OK, so what is the actual formula in AJ?
I am guessing it is calling upon some other cells, and it is entry in to these other cells that is populating AJ. Is that correct?
 
Upvote 0
Looking at it, i used an IF statement to reference another cell as i was thinking the LEN value might have something to do this.
however on reflection i think AI should be deleted if AO has an entry which is calculated. the formula is =SUM(AM7:AN7)

Hopefully this makes things easier.

Thanks again
Ross
 
Upvote 0

Forum statistics

Threads
1,215,895
Messages
6,127,624
Members
449,390
Latest member
joan12

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