【发布时间】:2018-02-15 23:01:41
【问题描述】:
听起来很简单:只需将日期存储在从单元格中获取的变量中。这就是我真正需要的。但我不断收到“需要对象”错误。
我有一个名为单元格的变量,我需要的信息是向左偏移两列和三列(所以 -2 和 -3 使用偏移量)。我尝试过使用字符串变量并使用 CDate() 对其进行转换,我尝试过使用整数并将其存储在那里,我尝试过 datevalue。我很茫然。这是我的代码的最新版本...
Function daysBetween(percent, quarters, cell As Range) As Boolean
'this function returns true if the date is past the allotted time for the group
cell.Select
Dim target As String
Dim issue As String
Dim targetCell As Range
Dim issueCell As Range
Set targetCell = ActiveCell.Value
Set targetCell = targetCell.Offset(0, -2)
Set issueCell = ActiveCell.Value
Set issueCell = issueCell.Offset(0, -3)
Set issue = DateValue(issueCell).Value
Set target = DateValue(targerCell).Value
If ((target - issue - (Date - target)) / (target - issue)) > (percent * quarters) Then
daysBetween = True
End If
End Function
谢谢,我很抱歉它有多乱......我正在自学 VBA,我 75% 的时间都不知道自己在做什么 :)
【问题讨论】: