View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default How do I use a default value or allow data entry to a cell

Enter the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set h2 = Range("H2")
Set h1 = Range("H1")
Set t = Target
If Intersect(t, h2) Is Nothing Then Exit Sub
If h1.Value = "Yes" Then Exit Sub
Application.EnableEvents = False
h2.Value = 10
Application.EnableEvents = True
End Sub


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

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

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 macros in general, see:

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

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

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


--
Gary''s Student - gsnu200830


"m4goaldad" wrote:

H2 has a default value of 10. H2 needs to be changeable by a user and the
amount allowed in H2 is infinite, but if H1 = "no" then H2 must equal 0. If
H1 = "Yes" the H2 must equal the amount entered, or if no amount is entered
by user, it must equal the default value of 10. How in the world do I do
that.