473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Limit decimal places with Excel automation

Hello everyone,

I was wondering if anybody could help with some Excel automation.

I have a form in Access, which exports the contents of a recordset to
Excel in the following manner:
objWS.Range("A2").CopyFromRecordset rstData, 1000
gobjExcel.Range("A1").Select

What I want to do, is check the contents of the exported data in Excel
automatically. If a cell contains a value with a decimal e.g. 123,456
then it must make the value only with 1 decimal place, e.g 123,46
Note: I do not want to truncate the values before I export them to
Excel.

Is there any easy way of doing this? Please help as I only started
automation recently.

Kind Regards,

Jean

Nov 13 '05 #1
2 5261
Rog
Here's some code I am using, you can adapt it for your needs:

Dim xlApp As Object, sheet As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open ("c:\data\spreadsheet1.xls")
Set sheet = xlApp.ActiveWorkbook.Sheets(1)
sheet.Range("C1:C10").NumberFormat = "0.00"

Nov 13 '05 #2
Hi Rog

thanks, that makes sense, but I am still unsure how I would loop
through a range of cells, and check them to see if they need to be
changed.

Something I imagined to look like this:

for Each cell in Worksheet.Cells
if (cell has more than 1 decimal place) then
cell.NumberFormat ="0.0"
end if
next cell

Know what I mean? Can someone please give a hint as to how the syntax
should be?

Thanks again for your help.

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
8
by: johkar | last post by:
How do I ensure a number has no more than 4 digits and 2 decimal places (adds .0 or .00 as necessary) onblur using reg expressions? Hints or solutions appreciated. John
2
by: David Nunn | last post by:
Need to preface that I am not much of an Access type. Doing I have several tables that have currency fields, which I run queries against to compare the figures in both. The data is imported from...
10
by: PeteCresswell | last post by:
Somebody posted same about a week ago, but I'm unable to find it. Could somebody put up a few lines of code that would ensure that a Double is stored with no more than, say, eight decimal places...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
6
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As...
4
by: Phil Mc | last post by:
OK this should be bread and butter, easy to do, but I seem to be going around in circles and not getting any answer to achieving this simple task. I have numbers in string format (they are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.