【发布时间】:2014-08-27 22:36:48
【问题描述】:
我正在尝试根据函数中的给定参数在不同的工作表上执行 VLOOKUP。我已经玩了几个小时,无法弄清楚为什么它不起作用。我尽可能多地减少代码进行测试,但无法有效地找到解决方案。我认为这可能是我如何从另一个工作表中为 VLOOKUP 调用范围的问题。代码如下。请指教。如果我不清楚我在问什么,请询问,我会提供反馈。谢谢
Function GraphDataA(cR As String, time As String, aClient As String, tps As String, dat As String)
Dim client As Boolean
Dim day As Boolean
Dim tot As Boolean
Dim dayTotData As Range
Dim dayTotDatas As Worksheet
Set dayTotDatas = ActiveWorkbook.Sheets("DayTot")
Set dayTotData = dayTotDatas.Range("A3:AI168")
client = False
day = False
tot = False
If date = "" Then
GraphDataA = ""
End If
If aClient = "" Then
GraphDataA = ""
End If
If cR = "Client" Then
client = True
End If
If time = "Day" Then
day = True
End If
If tps = "Total" Then
tot = True
End If
If client = True Then
If day = True Then
If tot = True Then
GraphDataA = WorksheetFunction.VLookup(aClient, dayTotData, WorksheetFunction.Match(dat, dayDate, 0) + 8, _
False)
End If
End If
End If
End Function
【问题讨论】:
标签: vba excel vlookup worksheet-function