Clear contents of cell based on value of another cell

STEVEMILLS04

Board Regular
Joined
Oct 8, 2009
Messages
113
How do I use event driven VBA to clear the contents of the cell within range K3:K300 if the data in cell J is not equal to "Promotable"? Obviously, if cell J3 is not Promotable then cell K3 should be cleared, etc...

Anytime cell J is changed the VBA should check K.

I am not very good with VBA but tried a few things and failed.

Thank you in advance.​
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
try below code
Code:
Sub Test()
Range("J3").Select
Do Until ActiveCell.Row = 300
If ActiveCell.Value = "Promotable" Then ActiveCell.Offset(0, 1).ClearContents
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
try below code
Code:
Sub Test()
Range("J3").Select
Do Until ActiveCell.Row = 300
If ActiveCell.Value = "Promotable" Then ActiveCell.Offset(0, 1).ClearContents
ActiveCell.Offset(1, 0).Select
Loop
End Sub

Kevatarvind,

I tried the code by pasting it to the sheet code but it did not work. Whenever J3 is changed to any value other than Promotable, cell K3 should be cleared. OF course, if J4 is changed, K4 should be cleared.
 
Upvote 0
what u need ?
you need that macro should run each time automatic if you changed the value ?
 
Upvote 0
i think you need code that run automatic so use below code on worksheet module
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each Cell In Range("J3:J300")
If UCase(Cell) = "PROMOTABLE" Then Cell.Offset(0, 1).ClearContents
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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