Excel(2010)VBA:将日期作为变量输入并存储

Excel(2010)VBA:将日期作为变量输入并存储,vba,excel,variables,Vba,Excel,Variables,听起来很简单:只需将日期存储在从单元格中提取的变量中。这就是我真正需要的。但我一直得到一个“需要对象”错误 我有一个名为cell的变量,我需要的信息是向左偏移两列和三列(使用offset时为-2和-3)。我尝试过使用字符串变量并用CDate()转换它,我尝试过使用整数并将其存储在那里,我尝试过datevalue。我不知所措。这是我的代码的最新版本 Function daysBetween(percent, quarters, cell As Range) As Boolean 'this fun

听起来很简单:只需将日期存储在从单元格中提取的变量中。这就是我真正需要的。但我一直得到一个“需要对象”错误

我有一个名为cell的变量,我需要的信息是向左偏移两列和三列(使用offset时为-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%的时间我都不知道自己在做什么:)

从值中删除s:

 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
Set targetCell = targetCell.Offset(0, -2)
Set issueCell = ActiveCell
Set issueCell = issueCell.Offset(0, -3)
issue = DateValue(issueCell).Value
target = DateValue(targerCell).Value
If ((target - issue - (Date - target)) / (target - issue)) > (percent * quarters) Then
    daysBetween = True
End If
End Function
我使用的是64位Excel 2016 MSO(16.0.8730.2175),下面是我使用的代码(编辑版本):

Dim worksheet_ As Worksheet
Set worksheet_ = Worksheets("NotTheNameOfMyWorksheet")

Dim columnNumber As Integer
Dim rowNumber As Integer

columnNumber = 1
rowNumber = 314

Dim cellValue As Variant
cellValue = worksheet_.Cells(rowNumber, columnNumber).Value

Dim date_ As Date
date_ = CDate(cellValue)

我终于在另一个问题上看到了这方面的一些东西(我已经在互联网上翻了一两个小时了)。它现在编译。。。但它也给了我一个“运行时错误91:对象变量或未设置块变量”…:(@seadoggie01对范围变量及其值使用不同的变量名。我不太明白,对不起……你能再解释一下吗?@gary的学生什么
Set
-s被删除了?你的示例代码与asker的完全相同,只是它不包含
偏移量
行。@KennyEvitt你是正确的ct…………我将删除此答案…………谢谢