如何在不修改电子表格的情况下返回修改范围
我想要我的vlookup_range()
服用byval
vba 范围
'search>'search'返回修改的范围对象,以= sumproducts使用(vlookup_range(H2:i2; a2:b11; 2); h3:i3)
,但也修改了表(键由值替换)。
我的猜测是,一个范围仅包含坐标和表键。
是否可以使用像我的示例这样的函数,也许与另一种对象类型一样?
Option VBASupport 1
Option Compatible
Function VLOOKUP_RANGE(ByVal range_to_modify, ref_range, index As Integer, Optional sorted As Boolean = False)
calc_built_in = getProcessServiceManager().createInstance("com.sun.star.sheet.FunctionAccess")
sheet = ThisComponent.getCurrentController.ActiveSheet
'VBA Range to LibreOffice
lo_ref_range = sheet.getCellRangebyName(ref_range.Address)
Dim sum
For Each cell In range_to_modify
If cell.Value <> 0 Then
cell.Value = calc_built_in.callFunction("VLOOKUP", Array(cell.Value, lo_ref_range, index, sorted))
End If
Next
VLOOKUP_RANGE = range_to_modify
End Function
I want my VLOOKUP_RANGE()
taking a ByVal
VBA Range
'search' to return a modified Range object, to use like =SUMPRODUCT(VLOOKUP_RANGE(H2:I2;A2:B11;2);H3:I3)
but the sheet is modified too (the keys are replace by the values).
My guess is that a Range contains only coords and a sheet key.
Is it possible to do use a function like my example, maybe with another object type ?
Option VBASupport 1
Option Compatible
Function VLOOKUP_RANGE(ByVal range_to_modify, ref_range, index As Integer, Optional sorted As Boolean = False)
calc_built_in = getProcessServiceManager().createInstance("com.sun.star.sheet.FunctionAccess")
sheet = ThisComponent.getCurrentController.ActiveSheet
'VBA Range to LibreOffice
lo_ref_range = sheet.getCellRangebyName(ref_range.Address)
Dim sum
For Each cell In range_to_modify
If cell.Value <> 0 Then
cell.Value = calc_built_in.callFunction("VLOOKUP", Array(cell.Value, lo_ref_range, index, sorted))
End If
Next
VLOOKUP_RANGE = range_to_modify
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在libreoffice中,可以写下这样的功能,例如,
如评论中所建议的那样,最好使用由Calc的内置功能组成的公式。
In LibreOffice, such a function can be written, for example, like this:
However, it is preferable to use formulas made up of Calc's built-in functions, as suggested in a comment.