Solved

Truncating a range

Posted on 2014-03-18
5
131 Views
Last Modified: 2014-03-18
I have the following code that selects a desired range:

Range(Range("StartEntry").Offset(0, 2), Range("TOTSALE").Offset(-2, 0)).Select

I would like to truncate antying in that range to only 2 decimal places.

Is this possible and if so how with VBA.
0
Comment
Question by:thandel
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:nutsch
Comment Utility
You can loop and round all cells in the range, like this

dim rgLoop as range

for each rgLoop in Range(Range("StartEntry").Offset(0, 2), Range("TOTSALE").Offset(-2, 0)).cells
rgloop=round(rgloop,2)
next rgloop

Open in new window

0
 

Author Comment

by:thandel
Comment Utility
Thanks but not looking to round, need to truncate.
0
 
LVL 39

Expert Comment

by:nutsch
Comment Utility
Then this

dim rgLoop as range

for each rgLoop in Range(Range("StartEntry").Offset(0, 2), Range("TOTSALE").Offset(-2, 0)).cells
rgloop=int(rgloop*100)/100
next rgloop

Open in new window

0
 

Author Comment

by:thandel
Comment Utility
Well its truncating but also making each empty cell's value "0.00"
0
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
Comment Utility
Here's an update:

dim rgLoop as range

for each rgLoop in Range(Range("StartEntry").Offset(0, 2), Range("TOTSALE").Offset(-2, 0)).cells
rgloop=iif(len(rgloop)=0,"",int(rgloop*100)/100)
next rgloop
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now