0
我已經嘗試了所有我知道的方法,但我無法使用其日期設置單元格值。我懷疑有一個小問題,但我不知道在哪裏。用函數返回的格式化日期填充單元格的值
Function getDates(strDateString) As Date
Dim x As Variant
x = Split(strDateString, "/")
If UBound(x) = 2 Then
strday = x(2)
strMonth = x(1)
strYear = x(0)
Else
strYear = Mid(strDateString, 1, 4)
strMonth = Mid(strDateString, 6, 2)
strday = Mid(strDateString, 8, 2)
End If
getDates = DateSerial(strYear, strMonth, strday)
End Function
For k = 11 To 12
strdates = getDates(Cells(2, k).Value)
Set Worksheets(strNewSheetName).Range(Cells(1, k), Cells(1, k)).Value = CStr(strdates)
MsgBox (strdates)
Next k
MsgBox
將返回正確的日期,但該值始終爲空!我試圖將它轉換爲以下每種方法的字符串:
cells(r,c).value
CSTR(strDates)
cdate()
但是這些都沒有奏效。
我試了一下,沒有設置,總是值爲空! – 2015-03-30 20:37:55
在我的測試中,如果我有'設置'那裏我得到'運行時錯誤對象所需'的錯誤。你能展示更多的代碼嗎?你有什麼不會自己編譯。循環不在任何類型的函數中 – Sobigen 2015-03-30 20:47:21