LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default formatting question

looks excellent, thanks so much
anny

"Ken Johnson" wrote in message
oups.com...
Hi anny,

You could try this Worksheet_Change Event Sub...

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo ERRORHANDLER
If Target.Column = 13 _
And Target.Row 7 _
And Target.Row < 38 _
And Target.Rows.Count = 1 _
And WorksheetFunction.IsNumber(Target.Value) _
And Target.Value < 10 _
And Mid(Target.Value, 2, 1) < "." Then
Application.EnableEvents = False
Dim strX() As String
Dim sShownValue As Single
Dim I As Byte
ReDim Preserve strX(1 To Len(Target.Value))
For I = 1 To UBound(strX)
strX(I) = Mid(CStr(Target.Value), I, 1)
Next
Select Case UBound(strX)
Case 1
sShownValue = CSng(strX(1) & "." & "000")
Case 2
sShownValue = CSng(strX(1) & "." & strX(2) & "00")
Case 3
sShownValue = CSng(strX(1) & "." & strX(2) & strX(3) & "0")
Case 4
sShownValue = CSng(strX(1) & "." & strX(2) & strX(3) & strX(4))
End Select
Target.Value = WorksheetFunction.Round(sShownValue, 3)
End If
If Target.Cells(1, 1).Value = 0 Then
Application.EnableEvents = False
Target.Cells(1, 1).ClearContents
Application.EnableEvents = True
Beep
Target.Select
End If
Application.EnableEvents = True
Exit Sub
ERRORHANDLER: Application.EnableEvents = True
End Sub


If the user enters a value with more than 4 digits the code assumes a
mistake has been made. The entry is cleared, the cell is reselected and
a beep is sounded.
If the user uses the decimal point, the code is skipped and the entry
is as usual.
If 10 is entered the code is skipped and it apears as 10.000.

Ken Johnson





 
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
Formatting Question CommMajor Excel Discussion (Misc queries) 3 December 11th 09 02:44 PM
Formatting Question Zecarioca Excel Discussion (Misc queries) 4 August 23rd 06 10:30 PM
Formatting Question denileigh[_6_] Excel Programming 3 February 8th 06 09:35 PM
Formatting Question M.Siler Excel Discussion (Misc queries) 3 July 18th 05 09:51 PM
Formatting Question Metalteck Excel Discussion (Misc queries) 1 July 15th 05 05:37 PM


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