Clear cell contents VBA code - 1 row at a time....

cabellos

New Member
Joined
Apr 2, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi,

I would really appreciate some assistance with the VBA code to clear the text from a cell if the cell text is updated to 'Closed'.

The two columns in question are K and M. When K8 is updated to 'Closed' (via drop down box) I want to clear the text in M8.

I want this coding to support this for each additional row in the same two columns (rows 8 : 100). E.g K9 & M9, K10 & M10 etc.

Thanks in advance for anyone who can support.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make selection in column K.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 11 Then Exit Sub
    If Target = "Closed" Then
        Target.Offset(, 2).ClearContents
    End If
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make selection in column K.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 11 Then Exit Sub
    If Target = "Closed" Then
        Target.Offset(, 2).ClearContents
    End If
    Application.ScreenUpdating = False
End Sub
Hi
 
Upvote 0
Hello. Have you tried the macro?
 
Upvote 0
Hi,

Many thanks for your swift reply. I really appreciate the support.

I did in fact try the macro and it worked. However, the cell it cleared included IF statements and unfortunately it also cleared this formula.

Not one to give up, I took another look at my IF statements and have amended these slightly to achieve what I wanted.

Many thanks for your support anyway as this code may still be useful.
 
Upvote 0
Does column M contain formulae?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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