Author Topic: How can I pass a "range" to a WorksheetFunction  (Read 540 times)

bhontz

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
How can I pass a "range" to a WorksheetFunction
« on: July 30, 2015, 09:26:16 PM »
I'm attempting to write an extension to the VLookup function.  I believe I'm having a problem when I attempt to pass an var[] array an Excel range to the VLookup function.

To illustrate:

@xl_func("string name, var[] r, int c: var")
def blookup(name, r, c):
    s = xl_app().WorksheetFunction.VLookup(name, r, c, False)
    return s

re: the above, I believe the problem is that the VLookup Worksheet method is expecting an Excel range and not a var[].

Is there a way to assign or cast an var[] to an Excel range that VLookup can digest?

Thanks in advance,

bhontz

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: How can I pass a "range" to a WorksheetFunction
« Reply #1 on: July 30, 2015, 11:00:52 PM »
(replying to my own thread)

I believe my question boils down to, how can you identify the cell addresses of an the cells in an array passed to a function?

I have their values, but as I'm looking to pass along the array to a WorksheetFunction I additionally need the Excel Range (the addresses of the cells) represented by the array's values.

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 544
  • Karma: +12/-1
    • View Profile
Re: How can I pass a "range" to a WorksheetFunction
« Reply #2 on: September 18, 2015, 10:15:24 AM »
Hi,

apologies for not replying to this earlier. Somehow I missed it...

Perhaps by now you have already figured this out, but you can use the type 'xl_cell' to pass a cell or range reference. You should be able to construct a Range object from the address property - see https://www.pyxll.com/docs/index.html#pyxll.XLCell for details.

Best regards,
Tony