Solved

excel and vb

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help formating a date variable in my VB.Net application 2 52
TT Auto Dashboard 13 92
Help me. 3 54
RUNRMTCMD from AS/400 12 46
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

770 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