Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 将日期和时间数据从单元格提取到VBA_Excel_Vba - Fatal编程技术网

Excel 将日期和时间数据从单元格提取到VBA

Excel 将日期和时间数据从单元格提取到VBA,excel,vba,Excel,Vba,我有一个excel文件,其中一列包含以下格式的日期:yyyy-mm-dd-h:mm 我想将日期和时间存储在两个单独的VBA字符串变量中。我将如何进行此操作?以字符串形式获取值: Sub ytrewq() ary = Split(Range("A1").Text, " ") DateAsString = ary(0) TimeAsString = ary(1) End Sub 要获取字符串形式的值,请执行以下操作: Sub ytrewq() ary = Split

我有一个excel文件,其中一列包含以下格式的日期:yyyy-mm-dd-h:mm


我想将日期和时间存储在两个单独的VBA字符串变量中。我将如何进行此操作?

以字符串形式获取值:

Sub ytrewq()
    ary = Split(Range("A1").Text, " ")
    DateAsString = ary(0)
    TimeAsString = ary(1)
End Sub

要获取字符串形式的值,请执行以下操作:

Sub ytrewq()
    ary = Split(Range("A1").Text, " ")
    DateAsString = ary(0)
    TimeAsString = ary(1)
End Sub

您可以使用Split函数提取两个不同变量中的日期和时间

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)  

您可以使用Split函数提取两个不同变量中的日期和时间

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)  

到目前为止你试过什么?你试过做任何研究吗?单元格是否将日期存储为序列日期?如果是,您可以从单元格中提取值2。它将是一个长数据类型值。整数部分表示日期和时间的分数。您可以研究有关搜索Excel序列日期的更多信息。到目前为止,您尝试了什么?你试过做任何研究吗?单元格是否将日期存储为序列日期?如果是,您可以从单元格中提取值2。它将是一个长数据类型值。整数部分表示日期和时间的分数。您可以研究有关搜索Excel序列日期的更多信息。