Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Formatting Excel from VB

Posted on 2001-08-15
9
Medium Priority
?
186 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

618 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