?
Solved

Formatting Excel from VB

Posted on 2001-08-15
9
Medium Priority
?
183 Views
Last Modified: 2012-05-04
Hi all,
 I have written a VB program that generates a formatted excel file from the recordset. Here are 2 of its columns
------------------------------------------------------
THIS IS THE HEADING PART

clmNumber = Len(Str(Int(3)))
clmName = Right(Str(Int(3)), clmNumber - 1)
clmRange = "a" & clmName
xls.Range(clmRange).Value = "Account"
   
clmNumber = Len(Str(Int(3)))
clmName = Right(Str(Int(3)), clmNumber - 1)
clmRange = "b" & clmName
xls.Range(clmRange).Value = "Shares"
-----------------------------------------------------
THIS IS THE PART WHERE DATA IS POPULATED
WITHIN A LOOP I HAVE

clmNumber = Len(Str(Int(i)))
clmName = Right(Str(Int(i)), clmNumber - 1)
clmRange = "g" & clmName
xls.Range(clmRange).HorizontalAlignment = xlHAlignLeft
xls.Range(clmRange).Borders.Weight = xlThin
xls.Range(clmRange).Value = rs!Account

clmNumber = Len(Str(Int(i)))
clmName = Right(Str(Int(i)), clmNumber - 1)
clmRange = "h" & clmName
a = Format(rs!Shares, "$###,###,###,###,##0.00")
xls.Range(clmRange).Style = "Currency"
xls.Range(clmRange).NumberFormat = "$###,###,###,##0.00"
xls.Range(clmRange).HorizontalAlignment = xlHAlignRight
xls.Range(clmRange).Borders.Weight = xlThin
xls.Range(clmRange).Value = a
--------------------------------------------------------
PROBLEM
 The shares part is displayed correctly ie. if 100 in the recordset then it is representes as $100.00.Perfect
 The account part is not ie. 123e67 becomes 1.23E+69 and 789e12 as 7.89E+14. It does formatting on its own and i think it is because of the "e". I was thinking of first converting the account to a text and then displaying it.
Got this idea because when you right-click on a cell and then click format-cell you get the option of displaying it as text and it works. But I dont know how to get that property to work from my code as I got it for displaying currency.

Any help
0
Comment
Question by:aspguru
[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
9 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6390611
xls.Range(clmRange).NumberFormat = "Text"
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6390616
From the help:   The format code is the same string as the Format Codes option in the Format Cells dialog box.
0
 

Expert Comment

by:cpearl_s
ID: 6391711
hai,
did u try converting the out coming recordset value to  CStr(value)
hope this works
regards
cpearl
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:aspguru
ID: 6392754
To PaulHews,
 I added the line to my code but still it does not work. Is there anything wrong that I am doing

-------------------------------------------------------
clmNumber = Len(Str(Int(i)))
clmName = Right(Str(Int(i)), clmNumber - 1)
clmRange = "g" & clmName
xls.Range(clmRange).NumberFormat = "Text"
xls.Range(clmRange).HorizontalAlignment = xlHAlignLeft
xls.Range(clmRange).Borders.Weight = xlThin
xls.Range(clmRange).Value = rs!Account
--------------------------------------------------------
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6392846
Oops.  Tried it myself; didn't work.  Opened an excel worksheet with a text formatting and found this.

xls.Range(clmRange).NumberFormat = "@"
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6392853
<ping>
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 400 total points
ID: 6392878
Looks like the formatting codes are actually the ones in the Custom format box.
0
 

Author Comment

by:aspguru
ID: 6393026
Thanks paul.  You were very helpful.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6393041
Happy to help.  Thanks for the points.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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