Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default index function in vba

Hello, I have a problem in vba. I am trying to use index function(which is an excel function) in vba. Let the function to be:


Function myfunc(a As Range)
mayfunc = Index(a, 1, 2)
End Function

However I get such an error "sub of function undefined" by highlighting "Index". In vba isn't index function defined? If not, what is its counterpart in vba? Thanks a lot. Best regards.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default index function in vba

hi Oercim,

Am Sat, 9 Mar 2013 10:24:12 -0800 (PST) schrieb oercim:

Function myfunc(a As Range)
mayfunc = Index(a, 1, 2)
End Function


try:
myfunc = WorksheetFunction.Index(a, 1, 2)


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default index function in vba

On Sat, 9 Mar 2013 10:24:12 -0800 (PST), oercim wrote:

Hello, I have a problem in vba. I am trying to use index function(which is an excel function) in vba. Let the function to be:


Function myfunc(a As Range)
mayfunc = Index(a, 1, 2)
End Function

However I get such an error "sub of function undefined" by highlighting "Index". In vba isn't index function defined? If not, what is its counterpart in vba? Thanks a lot. Best regards.


If you want to use an Excel function within VBA, you need to be specific (in computer talk). Not all Excel functions are useable within VBA.

Try WorksheetFunction.Index(...)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default index function in vba

Il 09/03/2013 19:24, oercim ha scritto:
Hello, I have a problem in vba. I am trying to use index function(which is an excel function) in vba. Let the function to be:


Function myfunc(a As Range)
mayfunc = Index(a, 1, 2)
End Function

However I get such an error "sub of function undefined" by highlighting "Index". In vba isn't index function defined? If not, what is its counterpart in vba? Thanks a lot. Best regards.


You can use directly range(row_number, column_number)

Function myfunc(a As Range)
mayfunc = a(1, 2)
End Function

Hi,
E.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default index function in vba

On Wednesday, March 13, 2013 9:16:04 PM UTC+11, plinius wrote:
Il 09/03/2013 19:24, oercim ha scritto:

Hello, I have a problem in vba. I am trying to use index function(which is an excel function) in vba. Let the function to be:






Function myfunc(a As Range)


mayfunc = Index(a, 1, 2)


End Function




However I get such an error "sub of function undefined" by highlighting "Index". In vba isn't index function defined? If not, what is its counterpart in vba? Thanks a lot. Best regards.






You can use directly range(row_number, column_number)



Function myfunc(a As Range)

mayfunc = a(1, 2)

End Function



Hi,

E.


One other point I would add to this, if you want to use worksheet functions in VBA you need to preface the function with WorksheetFunction or Application for example:

Sub IndexFunctionInVBA()
x = WorksheetFunction.Index(Range("C17:C32"), 1, 1)
MsgBox x
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using INDIRECT Function and INDEX Function ChristopherG Excel Discussion (Misc queries) 1 June 10th 09 04:07 PM
INDEX function John Case Excel Worksheet Functions 3 August 21st 08 07:13 AM
Index function altah Excel Worksheet Functions 7 December 13th 06 06:03 PM
Index Function/Match Function M Moore Excel Discussion (Misc queries) 3 September 3rd 06 11:49 AM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM


All times are GMT +1. The time now is 09:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"