Clearing cell contents on CellUpdate

loopoo

New Member
Joined
Nov 10, 2005
Messages
43
Hello all!

I want to do the following and I think VBA is the way to do it: when I change the content of a cell (let's say restricted ones: the cells in columns B or C), I want 3 cells to the right of the one updated to become empty.

I'm very very new to VBA so any code part would be appreciated.

Thanks in advance,
Chris
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to MrExcel - this code goes in the worksheet module of the sheet to be monitored for changes.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
<SPAN style="color:#00007F">If</SPAN> Intersect(Target, [B:C]) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">With</SPAN> Application
    .EnableEvents = <SPAN style="color:#00007F">False</SPAN>
    .ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
Range("D" & Target.Row & ":F" & Target.Row).Clear
<SPAN style="color:#007F00">' If C should be cleared on B, then</SPAN>
<SPAN style="color:#007F00">' range(target.offset(,1),target.offset(,3)).clear</SPAN>
<SPAN style="color:#00007F">With</SPAN> Application
    .EnableEvents = <SPAN style="color:#00007F">True</SPAN>
    .ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>

It is currently set up to clear D:F, but alternative syntax for C:E/D:F included.
 
Upvote 0

Forum statistics

Threads
1,226,588
Messages
6,191,889
Members
453,684
Latest member
Gretchenhines

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