[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Truncating a range

Posted on 2014-03-18
5
Medium Priority
?
142 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

650 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