View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default How can I have the fixed decinal places function for certain cells

On Mon, 28 Apr 2008 02:52:11 -0700, dleus
wrote:

I would like to avoid having to enter decimals points, but just for certian
cells, not the entire sheet.


I believe the only way to do that is with an event-triggered macro.

Here's one way that might work -- I don't know if I've checked for all the
possibilities, so make sure it works as you expect.

To enter this, right-click on the worksheet tab and select View Code.

Paste the code below into the module that opens.

Change AOI to refer to the cell(s) where you are interested in having a fixed
decimal. As written, it refers to Column A. (I coded to divide by 100, but if
you need a different value, or different values for different cells, that logic
can be incorporated).

Let me know if this does what you want.

===============================================
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim AOI As Range, c As Range
Set AOI = Range("A:A")
If Not Intersect(Target, AOI) Is Nothing Then
For Each c In Intersect(Target, AOI)
With c
If InStr(.Value, ".") = 0 And _
Len(.Value) 0 And _
.HasFormula = False And _
IsNumeric(.Value) Then
.Value = .Value / 100
End If
End With
Next c
End If
End Sub
=================================
--ron