Solved

excel and vb

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now