我对此非常绝望!
我已经构建了以下功能。 cday指的是具有日期的excel中的单元格,如01/01/2017
它匹配并找到数据集的行和列并将其输入到数组(dpricebase),我已预先填充数据通过子
我写了一个小子,它唤起它并且它有效。我尝试直接在excel使用它,但它没有!
请帮助!
谢谢你!Function findprice (cday, commno)
cday = DateValue(cday)
price1 = 0
If cday > lastday Then ‘last day is a date xx/xx/xxxx at a cell in the excel
price1 = 0
GoTo result
End If
Windows("m.xls").Activate
Sheets("Daily").Activate
‘find the matching row
For x = 5 To lastrow
If DateValue(Cells(x, 2)) = cday Then
datarow = Cells(x, 2).Row - 5
GoTo Continue1
End If
Next x
MsgBox "No data for " & cday & " for " & commno
Continue1:
'find the matching column
For y = 3 To totalcomm
If Cells(2, y) = commno Then
datacol = Cells(2, y).Column - 3
GoTo Continue2
End If
Next y
MsgBox "No Daily data for No." & commno
Continue2:
price1 = dpricebase(datarow, datacol)
GoTo result
result:
findprice = price1
End Function
答案 0 :(得分:2)
您的UDF存在一些问题: