Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clearing cell contents on CellUpdate


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


--
loopoo
------------------------------------------------------------------------
loopoo's Profile: http://www.excelforum.com/member.php...o&userid=28792
View this thread: http://www.excelforum.com/showthread...hreadid=484773

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Clearing cell contents on CellUpdate

First you need to know how to put the code into an event procedure (so it
runs when a particular event happens - in this case when a cell value is
changed). In the VBA editor show the Project Explorer (View menu, if not
showing already) and double-click on the sheet you want to do this on. Then,
at the top of the code pane note the two dropdown lists. Choose "Worksheet"
in the left one: the default event for the Worksheet is Selection Change so
the code pane will show a "blank" Worksheet_SelectionChange sub - you can
ignore this or erase it, doesn't matter. In the right dropdown box choose
"Change" and you should see:
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

This is the sub that will run when any cell on the sheet is changes - Target
will be the cell (or cells, in the event of a range of data being pasted or
cleared, etc.)

So this is the sub:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ChangedCell as Range

For Each ChangedCell in Target.Cells ' Loop through all cells that were
changed
With ChangedCell
' Check for column B or C and if so clear cell 3 columns to the right:
If .Column = 2 or .Column = 3 Then .Offset(0,3).ClearContents
End With
Next ChangedCell

End Sub

--
- K Dales


"loopoo" wrote:


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


--
loopoo
------------------------------------------------------------------------
loopoo's Profile: http://www.excelforum.com/member.php...o&userid=28792
View this thread: http://www.excelforum.com/showthread...hreadid=484773


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for clearing cell contents Sal Excel Discussion (Misc queries) 6 January 9th 09 11:40 PM
Clearing Contents of Cell Burt Excel Worksheet Functions 1 May 4th 05 02:46 PM
Clearing Cell Contents Lester Excel Programming 2 June 18th 04 10:31 PM
Clearing Cell Contents Lee Excel Programming 2 February 11th 04 10:23 PM
Clearing cell contents automatically Tom Ogilvy Excel Programming 2 August 21st 03 04:07 AM


All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"