multiple functions in worksheetfunction

jerry12302

Active Member
Joined
Apr 18, 2005
Messages
449
Office Version
  1. 2010
Platform
  1. Windows
I can have several different functions in one function in a cell in a worksheet, for example:

=INDEX(OFFSET(my1rangename,0,1),MATCH($A$1,my1rangename,0),1)

But I can't seem to do that in VBA with WorksheetFunction, the following will not work:

X = WorksheetFunction.Index(Offset(Range("my1rangename"),Match(myvariable, Range("my1rangename"), 0), 1)

I have to use multiple lines, and in this case, define a new range:

X = WorksheetFunction.Match(myvariable, Range("my1rangename"), 0)
Y = WorksheetFunction.Index(Range("mynewrange"),X, 1)

Is there a way to include multiple functions in one line of WorksheetFunction code?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Have you tried...

X = WorksheetFunction.Index(WorksheetFunction.Offset(Range("my1rangename"),WorksheetFunction.Match(myvariable, Range("my1rangename"), 0), 1)

Denis
 
Upvote 0
Yes, I tried that, I get a run time error

Object doesn't support this property or method.
 
Upvote 0
Is there a way to create a custom function in vba that could be called from any code in a module that would allow for this?
 
Upvote 0
Jerry, by taking a step back and looking at what you need to achieve, this is one solution:
Code:
Sub AlternateOffset()
  Dim X
  
  X = Range("Range2").Cells(WorksheetFunction.Match(Range("a1"), Range("Range2"), 0), 1).Offset(0, 1)
  Debug.Print X
  
End Sub
It doesn't get around using multiple WorksheetFunction calls, instead it combines one MATCH function with the VBA Offset method.

Denis
 
Upvote 0

Forum statistics

Threads
1,215,826
Messages
6,127,122
Members
449,361
Latest member
VBquery757

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top