Solved

excel and vb

Posted on 2006-06-14
5
197 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 add a minute to the date time value 8 64
Problem to skip loop 6 55
Sending a email via excel using vba 6 72
MsgBox 4 48
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 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…
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…
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…

863 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

19 Experts available now in Live!

Get 1:1 Help Now