Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Private Function Code Change

As part of a private function this code requires a value 1 to 12. How would
this code be modified to require the user to enter a value with two decimals.
For example 123.98. Blanks, non-number, and integer requirements are
already in place and working.

' Between 1 and 12?
If cell < 1 Or cell 12 Then
EntryIsValid = "Valid values are between 1 and 12."
Exit Function
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Private Function Code Change

I assume that data validation (Excel menu: Data- Validation) on the
worksheet is not an option; therefore, how about checking that the
third character from the right is a decimal point? Something like
if mid(cell, len(cell)-2, 1) < "."

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Private Function Code Change

Art,

The only requirement is for the entry to have two decimals, whatever the
number. here is what I did, using your and Ardus' replies:

' Two decimal entry required
If Mid(cell, Len(cell) - 2, 1) < "." Then
EntryIsValid = "Two-decimal entry required."
Exit Function
End If

I get a Run-time error '5': Invalid procedure call or argument, with the
line If Mid... highlighted yellow.


"Art H" wrote:

I assume that data validation (Excel menu: Data- Validation) on the
worksheet is not an option; therefore, how about checking that the
third character from the right is a decimal point? Something like
if mid(cell, len(cell)-2, 1) < "."


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Private Function Code Change

I'm sorry that I don't understand the context. Maybe "cell" is not
properly defined. Using ThisWorkbook and the change event, the
following code does the simple test and outputs a message--nothing
more.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Mid(Target.Value, Len(Target.Value) - 2, 1) < "." Then MsgBox
"Invalid"
End Sub

HTH,

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Private Function Code Change

P.S. You might need to add error checking in case the input is less
than three characters. Mid does not like the second parameter to be
less than 1.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Private Function Code Change

Function EntryIsValid(cell As Range)
With cell
EntryIsValid = _
.Value = 1 And _
.Value <= 12 And _
Round(.Value, 2) = .Value
End With
End Function

HTH
--
AP

"Phil H" a écrit dans le message de
...
As part of a private function this code requires a value 1 to 12. How

would
this code be modified to require the user to enter a value with two

decimals.
For example 123.98. Blanks, non-number, and integer requirements are
already in place and working.

' Between 1 and 12?
If cell < 1 Or cell 12 Then
EntryIsValid = "Valid values are between 1 and 12."
Exit Function
End If



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
difference between a private sub and a public function? Dave F Excel Discussion (Misc queries) 4 March 16th 07 07:38 PM
Calling Private Sub/Function AMK4[_36_] Excel Programming 5 February 4th 06 01:47 AM
private variable: same module, other Sub/Function Stefi Excel Programming 4 July 5th 05 09:10 AM
Add code to Private Sub ComboBox1_Change() with a macro from a different workbook help_wanted[_2_] Excel Programming 4 April 2nd 04 06:47 PM
Call Private Function from ThisWorkbook module Beto[_3_] Excel Programming 3 February 25th 04 01:36 PM


All times are GMT +1. The time now is 08:22 AM.

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"