473,804 Members | 5,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ").CopyFromReco rdset rstData, 1000
gobjExcel.Range ("A1").Selec t

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 5283
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("E xcel.Applicatio n")
xlApp.Workbooks .Open ("c:\data\sprea dsheet1.xls")
Set sheet = xlApp.ActiveWor kbook.Sheets(1)
sheet.Range("C1 :C10").NumberFo rmat = "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.NumberForm at ="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
4543
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
6157
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
8
6170
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
2870
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 Excel spreadsheets supplied by different parties, over which I have no control. My problem is that whilst several parties supply the spreadsheets with the currency fields containing two figures to the right of the decimal place (ie 123.51,...
10
2309
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 worth of precision? VBA or SQL....I'm guessing the logic is the same.
8
11331
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
6350
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
598
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 Excel.Range
4
9499
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 coming in from an excel sheet): Examples. 45,666.0041 5664456.12 -5465.25568 ETC
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.