ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Numeric column in Excel (https://www.excelbanter.com/excel-programming/331595-numeric-column-excel.html)

KK[_4_]

Numeric column in Excel
 
Hi,

Please check the code snippet below. I want the 4th column be numeric.
But, in the result it is always showing as text.

Any suggestions to show this column as numeric?

Thanks.




XLSConn = New ADODB.Connection
XLSConn.Open("Provider=Microso*ft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDestination & _
";Extended Properties=""Excel 8.0;HDR=NO;""")


Dim source As String
Dim arrData
Dim Counter As Integer
source = "Select * from [A6:G6" & "$" & strRecRange &
"]"
XLSrs.Open(source, XLSConn, 1, 3)
arrData = Split(strRec, Chr(9))

For Counter = LBound(arrData) To UBound(arrData) - 1
If Counter = 4 Then 'this column must be integer
XLSrs.Fields(Counter).Value =
Integer.Parse(arrData(Counter))
Else
XLSrs.Fields(Counter).Value = Left(arrData(Counter),
255)
End If
Next


XLSrs.Update()
XLSrs.Close()


eddybarzoom

Numeric column in Excel
 
i am not sure, but are arrays in Excel zero based? If so then the first
column is array index(0), and the fourth column is array index(3), not
array(4).





"KK" wrote:

Hi,

Please check the code snippet below. I want the 4th column be numeric.
But, in the result it is always showing as text.

Any suggestions to show this column as numeric?

Thanks.




XLSConn = New ADODB.Connection
XLSConn.Open("Provider=MicrosoÂ*ft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDestination & _
";Extended Properties=""Excel 8.0;HDR=NO;""")


Dim source As String
Dim arrData
Dim Counter As Integer
source = "Select * from [A6:G6" & "$" & strRecRange &
"]"
XLSrs.Open(source, XLSConn, 1, 3)
arrData = Split(strRec, Chr(9))

For Counter = LBound(arrData) To UBound(arrData) - 1
If Counter = 4 Then 'this column must be integer
XLSrs.Fields(Counter).Value =
Integer.Parse(arrData(Counter))
Else
XLSrs.Fields(Counter).Value = Left(arrData(Counter),
255)
End If
Next


XLSrs.Update()
XLSrs.Close()




All times are GMT +1. The time now is 12:12 PM.

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