ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Converting Data Types (https://www.excelbanter.com/excel-programming/359743-converting-data-types.html)

news.microsoft.com[_10_]

Converting Data Types
 
I'm dumping data into an Excel sheet via DTS from SQL Server. But I can't figure out how to get the numbers to come across as numbers. They come across as text and the formulas in the sheet are choking because they are expecting to sum numbers.

So I figured I'd just convert the data programmatically from text to numbers.

Changed the NumberFormat property and it doesn't help.
Tried messing with the PrefixCharacter property, but it's read only.

How can I get the values to convert from text to number? Excel offers the option as a SmartTag, but I can't find any method that will do it programmatically. Thanks.

Jerry

news.microsoft.com[_10_]

Converting Data Types
 
Nevermind... All I had to do was reassign the same value to the cell after setting the NumberFormat property.
"news.microsoft.com" wrote in message ...
I'm dumping data into an Excel sheet via DTS from SQL Server. But I can't figure out how to get the numbers to come across as numbers. They come across as text and the formulas in the sheet are choking because they are expecting to sum numbers.

So I figured I'd just convert the data programmatically from text to numbers.

Changed the NumberFormat property and it doesn't help.
Tried messing with the PrefixCharacter property, but it's read only.

How can I get the values to convert from text to number? Excel offers the option as a SmartTag, but I can't find any method that will do it programmatically. Thanks.

Jerry

Tom Ogilvy

Converting Data Types
 
It is pretty much a matter of stimulating Excel to reevaluate the value:

Sub convertBack()
Dim cell as Range
For each cell in selection
if not cell.Hasformula then
if isnumeric(trim(cell.Text)) then
cell.Numberformat = "general"
cell.formula = cdbl(trim(Replace(cell.value,chr(160),"")))
end if
end if
Next
end Sub



--
Regards,
Tom Ogilvy




"news.microsoft.com" wrote:

I'm dumping data into an Excel sheet via DTS from SQL Server. But I can't figure out how to get the numbers to come across as numbers. They come across as text and the formulas in the sheet are choking because they are expecting to sum numbers.

So I figured I'd just convert the data programmatically from text to numbers.

Changed the NumberFormat property and it doesn't help.
Tried messing with the PrefixCharacter property, but it's read only.

How can I get the values to convert from text to number? Excel offers the option as a SmartTag, but I can't find any method that will do it programmatically. Thanks



All times are GMT +1. The time now is 08:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com