Solved

excel and vb

Posted on 2006-06-14
5
203 Views
Last Modified: 2010-04-30
I have a program that populates an excel spreadsheet.

When I have numbers like below stored into my db (as a string), I can populate without a problem.
+3.205539E-05

When I use a number stored as a string like .000032 and format it like
Format(tmpRS("calculatedValue"), "#.0000E+00") it works well.

When I try to add a "+" sign before it, it will not show up in excel.

so

"+" & Format(tmpRS("calculatedValue"), "#.0000E+00") strips the "+"

since everything is a string, why does it work when it comes out of the db in that format, but it won't work when I build it on the fly?



0
Comment
Question by:jackjohnson44
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16907746

that is because it is stored as a string, and it comes out as a string

when you build on the fly, it gets stored as string, but without the + sign, because excel formats it before storing it
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 16910528
how about

"'+" & Format(tmpRS("calculatedValue"), "#.0000E+00")

' add single quote in front
0
 

Author Comment

by:jackjohnson44
ID: 16911337
I can't put a single quote in front of it.

Why does excel format the string that I build, but the string that comes out of the db does not get formatted?

If I assign the database value to a string, then write it to excel, the "+" gets dropped.

            tmpMeas = tmpRS("measure")
            xlsheet.Cells(counter, 12).value = tmpMeas
shows
   "3.21E-05"

while
            xlsheet.Cells(counter, 12).value = tmpRS("measure")
shows
   "+3.21E-05"

how do I get writing a variable to behave the same way using a recordset does?

The value is stored in a database as type string.
0
 

Author Comment

by:jackjohnson44
ID: 16911608
I was able to get it to work by assigning the value to the recordset, then printing the value from the recordset.
Is there a reason I can't do this by assigning it to a variable?

This works:

            If Len(tmpRS("calculatedValue")) Then
                tmpRS("calculatedValue") = " +" & Format(tmpRS("calculatedValue"), "#.0000E+00")
            Else
                tmpRS("calculatedValue") = ""
            End If
               
            xlsheet.Cells(counter, 13).value = tmpRS("calculatedValue")
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16911638
xlsheet.Cells(counter, 12).value = tmpRS("measure")


when you do this what is the format cell tell you
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 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