[英]Extracting Date and time data from Cell to VBA
我有一個Excel文件,該文件的列包含以下格式的日期:yyyy-mm-dd h:mm
我想將日期和時間存儲在兩個單獨的VBA字符串變量中。 我將如何處理?
要獲取字符串形式的值:
Sub ytrewq()
ary = Split(Range("A1").Text, " ")
DateAsString = ary(0)
TimeAsString = ary(1)
End Sub
您可以使用拆分功能提取兩個不同變量中的日期和時間。
Dim aDate() As String
Dim separatedDate As String
Dim separatedTime As String
'Put the value before the " " (space character) in the first case of the array
'and the value after the " " (space character) in the second case
aDate = Split(Range("Cell where you date is").Value, " ", -1)
'You can now access these values and store them in variables
separatedDate = aDate(0)
separatedTime = aDate(1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.