# Controlling the Decimal Places

EE Pros,

I have Two Worksheets in a Workbook (attached) that change Currency Formatting when a new Currency is selected.  A table controls the decimal points on the results.  I have some fields that require 2 Decimals and some that require -0- (i.e. numbers ranging from .15 to 150000000.  So you see the need for controlling the decimal points at the end result cell.

I'm hoping there is a simple way to do this but I have tried changing the Cell Formatting (which reverts to the table when the currency changes).  Any ideas?

B.
Suppress-decimalsv4.xlsm
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
Sorry. I had a question here but I figured it out. Will get back to you.
0
Older than dirtCommented:
Try this where I added/modified lines 19 to 24.

``````Private Sub Worksheet_Change(ByVal Target As Range)
Dim rFind As Range, rStep As Range
Dim sSheet As String, sRange As String
Dim strNF As String

If Target.Cells.Count > 1 Then Exit Sub
Set rFind = Me.Range(CurrencyList).Find(What:=Target.Value, LookAt:=xlWhole)
If Not rFind Is Nothing Then
For Each rStep In Me.Range(Me.Range(ChangeCellStart), Me.Cells(Me.Rows.Count, Me.Range(ChangeCellStart).Column).End(xlUp))
On Error Resume Next
If InStr(1, rStep.Value, "!") = 0 Then
Me.Range(rStep.Value).NumberFormat = rFind.Offset(0, 1).NumberFormat
Else
sSheet = Trim(Left(rStep.Value, InStr(1, rStep.Value, "!") - 1))
sRange = Trim(Right(rStep.Value, Len(rStep.Value) - InStr(1, rStep.Value, "!")))
If Left(sSheet, 1) = "'" Then sSheet = Right(sSheet, Len(sSheet) - 1)
If Right(sSheet, 1) = "'" Then sSheet = Left(sSheet, Len(sSheet) - 1)
If sRange = "C9" Then
strNF = rFind.Offset(0, 1).NumberFormat
Else
strNF = Replace(rFind.Offset(0, 1).NumberFormat, ".00", "")
End If
ThisWorkbook.Worksheets(sSheet).Range(sRange).NumberFormat = strNF
End If
On Error GoTo 0
Next rStep
End If
End If
End Sub
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Sorry for the delay; Let me try this and get back with you in 24 hrs.  On the road....

Thank you,

B.
0
Older than dirtCommented:
You may still be unpacking but did you get a chance to test this?
0
Author Commented:
MartinLiss,

I am so sorry to have taken so long in testing this.  It worked perfectly!  I just got in to South Africa and it's the only excuse I have for not getting back with you sooner.  Thank you so much!  I may author a slightly different question about how to address the same requirement on a different "sheet".

Thanks again,

B.
0
Older than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.