【发布时间】:2018-05-22 03:06:37
【问题描述】:
我需要在 Excel VBA 中处理来自不同工作表的单元格范围。 这是我的代码:
Function LastDayForClient(client As String, mnth As Integer, dates As range) As String
Dim dtRow As Date
Dim dt As range
dtRow = 0
For Each dt In dates
' If not that month that we are looking for - go next
If month(dt.Value) = mnth Then
' If not that client - go next
If Cells(dt.Row, dt.Column + 1).Value = client Then
If dtRow = 0 Then
dtRow = dt.Value
ElseIf dtRow < dt.Value Then
dtRow = dt.Value
End If
End If
End If
Next dt
LastDayForClient = Format(dtRow, "dd.mm.yyyy")
End Function
这就是我想使用公式的方式:
=LastDayForClient("Client_name";5;Diff_sheet!G6:G297)
我想我以某种错误的方式使用了传递的Range 参数,因为在不同的工作表上使用公式时我得到了错误的值。当范围在同一张纸上时,一切都很好。
【问题讨论】:
-
为什么要使用格式,
month(dt.Value2)不需要额外的步骤就不能工作? -
感谢您的评论@ScottCraner!不知道我为什么那样使用它。无论如何,范围是什么?