How can I have the fixed decinal places function for certain c
On Tue, 29 Apr 2008 04:45:02 -0700, dleus
wrote:
I apoligize for not being clear on what I'm trying to do.
What I need is for 1 col to be divided by 100 and another col to be divide
by 10. One col is a price ($) and the other col is a quantity that has 1
digit after the decimal. I'm trying to get it so that I don't have to enter
the decimal points all the time.
Your code is working great for me, I just don't know how to set it up for 2
different cols and 2 different divisors.
Thanx for your patience
doug
Something like this for Columns A/100 and D/10 should give you some ideas.
===============================
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim AOI As Range, c As Range
Set AOI = Range("A:A,D:D")
If Not Intersect(Target, AOI) Is Nothing Then
Application.EnableEvents = False
For Each c In Intersect(Target, AOI)
With c
If VarType(.Value) = 2 And _
VarType(.Value) <= 6 And _
.HasFormula = False Then
If .Value = Int(.Value) Then
Select Case c.Column
Case Is = 1 'Column A
.Value = .Value / 100
Case Is = 4 'Column D
.Value = .Value / 10
End Select
End If
End If
End With
Next c
End If
Application.EnableEvents = True
End Sub
===============================
Also, please note that this routine does NOT work the same as the "Fixed
Decimal" selection in Excel. In particular, it will divide any integer. So
entries in Column A of
12
12.
12.00
will all be converted to 0.12
If you want to enter an integer, you must follow it by two zeros in a "divide
by 100" column, and by a single zero in a "divide by 10" column.
A1: 1200 -- 12
D1: 120 -- 12
--ron
|