Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I use a default value or allow data entry to a cell

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How do I use a default value or allow data entry to a cell

Hi,

Right click your sheet tab, view code and paste this in.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$H$2" Then Exit Sub
Application.EnableEvents = False
If UCase(Range("$H1").Value) = "NO" Then
Target.Value = 10
End If
Application.EnableEvents = True
End Sub

Mike

"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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
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.

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
Can I lock a cell after data entry so entry can not be changed Verlinde Excel Discussion (Misc queries) 3 April 22nd 10 07:59 PM
Control Data Entry - push entry to next cell Ofelia Excel Discussion (Misc queries) 0 July 7th 08 04:19 PM
Delete cell entry and default contents are restored, for multiplerows [email protected] Excel Programming 3 July 1st 08 10:12 PM
Default colour in cell based on specific entry KCG Excel Worksheet Functions 4 August 5th 07 09:26 AM
Cell Entry That Locks Selected Cells From Any Data Entry. ron Excel Worksheet Functions 5 February 16th 07 09:52 PM


All times are GMT +1. The time now is 04:10 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"