楼主的 A 列是日期时间型数据(= Double),什么点杠斜都不包含。不要把内存数据和显示内容混为一谈。可以把 Excel 用作 Jet Engine 的外部数据库来处理。假定你已经在 Excel 上建立了连接,且 Excel 表的首行有字段名(datDate, strDate):Update [Sheet1$] Set strDate = Format(datDate, 'YYYY-MM-DD')
各位大侠: 我的文件有60行需要变化,没有表头,时间格式有2009-6-10,有2009-6-6; 即长短字符数不一样;我的程序如下:For C = 2 To 60 cells(C, 20) = CStr(cells(C, 19)) next不行,出错:subscrap out of range 更改为: For C = 2 To 60 cells(C, 20) = format(cells(C, 19)) next出错:sub or function not defined如何更正
Sub test() Dim c As Integer
Columns(2).NumberFormatLocal = "@"
For c = 2 To 60 Cells(c, 2) = CStr(Format(Cells(c, 1), "yyyy-mm-dd")) NextEnd Sub
Sub test() Dim c As Integer
Columns(20).NumberFormatLocal = "@"
For c = 2 To 60 Cells(c, 20) = CStr(Format(Cells(c, 19), "yyyy-mm-dd")) Next End Sub
Sub okexcel() Cells(1, "B") = "'" & Cells(1, "A").Text End Sub如此简单 加上循环就行了!
Dim s1 As String, s2 As String
S1 = "2009.09.08"
s2 = Format(s1, "YYYY-MM-DD")
Dim d As Date
Dim s As String
d = #8/6/2009#
s = CStr(d)
MsgBox s
End Sub
如果含".",那就用format吧
楼主的 A 列是日期时间型数据(= Double),什么点杠斜都不包含。不要把内存数据和显示内容混为一谈。可以把 Excel 用作 Jet Engine 的外部数据库来处理。假定你已经在 Excel 上建立了连接,且 Excel 表的首行有字段名(datDate, strDate):Update [Sheet1$] Set strDate = Format(datDate, 'YYYY-MM-DD')
我的文件有60行需要变化,没有表头,时间格式有2009-6-10,有2009-6-6; 即长短字符数不一样;我的程序如下:For C = 2 To 60
cells(C, 20) = CStr(cells(C, 19))
next不行,出错:subscrap out of range
更改为:
For C = 2 To 60
cells(C, 20) = format(cells(C, 19))
next出错:sub or function not defined如何更正
Dim c As Integer
Columns(2).NumberFormatLocal = "@"
For c = 2 To 60
Cells(c, 2) = CStr(Format(Cells(c, 1), "yyyy-mm-dd"))
NextEnd Sub
Dim c As Integer
Columns(20).NumberFormatLocal = "@"
For c = 2 To 60
Cells(c, 20) = CStr(Format(Cells(c, 19), "yyyy-mm-dd"))
Next End Sub
Cells(1, "B") = "'" & Cells(1, "A").Text
End Sub如此简单
加上循环就行了!
Range("B1").Select
ActiveCell.FormulaR1C1 = "=TEXT(RC[-1],""yyyy-mm-dd"")"
Selection.AutoFill Destination:=Range("B1:B60"), Type:=xlFillDefault
Range("B1").Select
回复8楼:
你的方法有效,能否解释一下
Columns(20).NumberFormatLocal = "@" 谢谢