Excel(2010)VBA:将date作为variables并存储

听起来很简单:只需将一个date存储在一个从单元格中获取的variables中。 这就是我真正需要的。 但是我不断收到一个“Object required”错误。

我有一个名为单元格的variables,我需要的信息是左侧偏移两列和三列(所以-2和-3使用偏移量)。 我曾尝试使用stringvariables并将其转换为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%的时间:)

从值中删除Set s:

 Set targetCell = ActiveCell.Value Set issueCell = ActiveCell.Value Set issue = DateValue(issueCell).Value Set target = DateValue(targerCell).Value 

你只需要设置范围对象。