Solved

Truncating a range

Posted on 2014-03-18
5
138 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

730 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