Solved

Truncating a range

Posted on 2014-03-18
5
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 39938556
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
ID: 39938579
Thanks but not looking to round, need to truncate.
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39938585
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
ID: 39938602
Well its truncating but also making each empty cell's value "0.00"
0
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39938645
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

690 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