close

I am having a problem with numbers being stored as text in Excel. I am
exporting the data from a SQL Server dB using a DTS package. I have tried
converting the fields before export in DTS and this does seem to work
temporarily, but the Excel file will eventually convert to all text.

I have read the help regarding converting these fields from quot;numbers stored
as textquot; to numbers, and have forwarded that information on to the end users.
However, this can be only a temporary solution, as the end users do not want
to do this every day.

Thanks in advance for any help!

If the data is contiguous you can modify the following VBA code to convert
the string values to numeric values. This way your staff can just run a
macro following the retrieval of the data, which might make it easier for
them.

Sub TextToVal()

Dim wb As Workbook
Dim ws As Worksheet
Dim strVal As String
Dim lngVal As Long
Dim lCounter As Long
Dim r As Range

Set wb = ActiveWorkbook
Set ws = wb.Worksheets(quot;Sheet1quot;)
ws.Activate
Range(quot;A1quot;).Select

Selection.CurrentRegion.Select
Selection.Name = quot;MyDataquot;
Set r = Range(quot;MyDataquot;)

For lCounter = 1 To r.Cells.Count
strVal = CStr(r.Cells(lCounter).Value)
lngVal = CLng(strVal)
r.Cells(lCounter).Value = lngVal
Next lCounter

Set wb = Nothing
Set ws = Nothing
Set r = Nothing

End Sub

--
Kevin Backmannquot;Thorkilquot; wrote:

gt; I am having a problem with numbers being stored as text in Excel. I am
gt; exporting the data from a SQL Server dB using a DTS package. I have tried
gt; converting the fields before export in DTS and this does seem to work
gt; temporarily, but the Excel file will eventually convert to all text.
gt;
gt; I have read the help regarding converting these fields from quot;numbers stored
gt; as textquot; to numbers, and have forwarded that information on to the end users.
gt; However, this can be only a temporary solution, as the end users do not want
gt; to do this every day.
gt;
gt; Thanks in advance for any help!

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()