Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default entering a validated value into a cell

I would like to know if I can prevent a certain value being entered into a
cell if the preceeding cell has acertain value. For example if cell 1A has
the value N entered in it can I prevent the value E being placed into cell
1B, obviously if any other value is in cell 1A I want to be able to enter the
value E. This is not a validating issue as I am also using validation rules
so that only certain values can be put into cells.
Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default entering a validated value into a cell

Try this tiny worksheet event macro. It is only an example for cells A1 and
B1:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set a = Range("A1")
Set b = Range("B1")
If Intersect(t, b) Is Nothing Then Exit Sub
If a.Value < "N" Then Exit Sub
If b.Value < "E" Then Exit Sub
MsgBox ("E is not valid, try again")
Application.EnableEvents = False
b.ClearContents
b.Select
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200771


"Sadcrab" wrote:

I would like to know if I can prevent a certain value being entered into a
cell if the preceeding cell has acertain value. For example if cell 1A has
the value N entered in it can I prevent the value E being placed into cell
1B, obviously if any other value is in cell 1A I want to be able to enter the
value E. This is not a validating issue as I am also using validation rules
so that only certain values can be put into cells.
Thanks in advance

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
Multiple selection from and into validated cell. Vikas Kumar Excel Discussion (Misc queries) 6 September 3rd 08 08:40 PM
Tab from a Validated Cell to another shad Excel Discussion (Misc queries) 4 February 4th 07 09:21 PM
cell data not validated if navigating cell to cell with mouse LoveThatMouse Excel Worksheet Functions 6 May 21st 06 09:03 PM
be validated or not validated in a cell x taol Excel Programming 1 November 22nd 05 01:36 AM
Display background color of a cell in a Validated cell Infoseeker Excel Programming 9 April 26th 05 08:40 PM


All times are GMT +1. The time now is 12:14 PM.

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

About Us

"It's about Microsoft Excel"