Convert to Text Format In Excel

女生的网名这么多〃 提交于 2019-12-24 23:23:41

问题


I'm extracting some data from AS400 using excel macro. In the AS400, this particular column (Ref), shows 20100729000078154 but when I extracted it to excel, it will be 2.01007E+16. I need to hv 20100729000078154 as my final output. This is the macro that I used to extract the info from AS400 :-

Sub Extract()

Dim StrSQl As String

FromA = Format(Sheet1.Range("B3"))
FromB = Format(Sheet1.Range("B4"))
FromC = Format(Sheet1.Range("B5"))
FromD = Format(Sheet1.Range("B6"))

StrSQl = "select Cno,Itno,Ref from test "
StrSQl = StrSQl & " where Cno= " & FromA & " and Itno like " & FromB & " and "
StrSQl = StrSQl & " Ref >= " & FromC & " and  Ref <= " & FromD & " "
StrSQl = StrSQl & " order by Cno "

con = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User Id=yyyyy;Password=zzzzz"

Set Db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
Db.ConnectionString = con
Db.Open


rs.Open StrSQl, Db, 3, 3

Sheet2.Cells(1, 1).CopyFromRecordset rs

rs.Close

Set rs = Nothing
Set cn = Nothing

End Sub

回答1:


You can prefix an apostrophe if you're just wanting the column to display as text, something like (assuming a single apostrophe literal can be expressed as '' in iSeries SQL)...

StrSQl = "select Cno,Itno,CONCAT('''',Ref) as Ref from test "


来源:https://stackoverflow.com/questions/3852387/convert-to-text-format-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!