Solved

Excel formatting

Posted on 1998-11-04
4
123 Views
Last Modified: 2010-04-30
I am using excel as Object in VB 5.0. I am getting the values of the cell in excel as
Value = xlSheet.Cells(1, 1). But the problem is if the excel cell is having 123.450
as the value it is returning 123.45 instead of 123.450. I want to get 123.450 from the excel and as well I want the excel to save the file with 123.450 instead of 123.45 as it normally does.

Can anybody help me out in this issue.
0
Comment
Question by:lesa
  • 2
4 Comments
 
LVL 9

Expert Comment

by:david_levine
ID: 1443130
Well, you can't really... cause you are retreiving the value of the cell and that value doesn't have the trailing zero. It shows like that because of the format statements. I'm not 100% sure how to retrieve the format statements if you need to, but you should be able to show it that way in VB with an appropriate edit mask.

David
0
 
LVL 3

Accepted Solution

by:
tcurtin earned 10 total points
ID: 1443131
Try Value = format(xlSheet.Cells(1, 1),"#.000")
This will force 3 decimals.
0
 

Author Comment

by:lesa
ID: 1443132
I have no fixed decimals to make use of the above format. What all I want is if the user enters 123.450 it should save like that instead of 123.45. The decimals may vary like 123.4560 then it should save as 123.4560 instead of 123.456.
0
 
LVL 3

Expert Comment

by:tcurtin
ID: 1443133
looks like you want floating zeros. Why would you like a zero on the end if there are no values in that column? You could use the 'lostfocus' event to set the value:

text1.text = text1.text & "0"

That way you will always append a zerol
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now