Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AJ AJ is offline
external usenet poster
 
Posts: 99
Default VBA does not recognize Excel worksheet function "indirect"

I have a piece of Excel code as follows

Public Function Refer(ByVal SheetName, ByVal CellName) As Variant
Dim cellref As String
cellref = "'" & SheetName & "'!" & CellName
Refer = Indirect(cellref)
End Function

When I compile this VBA project, I get a 'function not defined' error on the
Indirect function.

Any ideas? I have ensured all VBA libraries are referenced.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA does not recognize Excel worksheet function "indirect"


AJ;165121 Wrote:
I have a piece of Excel code as follows

Public Function Refer(ByVal SheetName, ByVal CellName) As Variant
Dim cellref As String
cellref = "'" & SheetName & "'!" & CellName
Refer = Indirect(cellref)
End Function

When I compile this VBA project, I get a 'function not defined' error
on the
Indirect function.

Any ideas? I have ensured all VBA libraries are referenced.


Hello AJ,

You're right. VBA doesn't support the worksheet function "Indirect".
You can achieve the this by taking the Range of a Range.

Refer = Range(Range(cellref))

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45837

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 293
Default VBA does not recognize Excel worksheet function "indirect"

Hi AJ,

INDIRECT is not one of the Worksheet Functions available to VBA - see "List of Worksheet Functions Available to Visual Basic" in
Excel's help file.

--
Cheers
macropod
[MVP - Microsoft Word]


"AJ" wrote in message ...
I have a piece of Excel code as follows

Public Function Refer(ByVal SheetName, ByVal CellName) As Variant
Dim cellref As String
cellref = "'" & SheetName & "'!" & CellName
Refer = Indirect(cellref)
End Function

When I compile this VBA project, I get a 'function not defined' error on the
Indirect function.

Any ideas? I have ensured all VBA libraries are referenced.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VBA does not recognize Excel worksheet function "indirect"

Normally to call a worksheet function in VBA need to do it like this
result = Application.WorksheetFunction.funcName()

However, as macropod has pointed out, Indirect is not an available
WorksheetFunction.

But why not simply -
Refer = Range(cellref).Value

or
Refer = Worksheets(SheetName).Range(CellName).Value

or if you already have a reference to the sheet as is typically the case
Refer = ws.Range(CellName).Value

(using your argument names and assuming all is to refer to the Active
workbook)

Regards,
Peter T


"AJ" wrote in message
...
I have a piece of Excel code as follows

Public Function Refer(ByVal SheetName, ByVal CellName) As Variant
Dim cellref As String
cellref = "'" & SheetName & "'!" & CellName
Refer = Indirect(cellref)
End Function

When I compile this VBA project, I get a 'function not defined' error on
the
Indirect function.

Any ideas? I have ensured all VBA libraries are referenced.



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
Turn off "CALCULATE" on bottom of Excel worksheet. near "Ready" chrispal86 Excel Discussion (Misc queries) 2 February 2nd 10 08:36 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Excel "Worksheet Name" Building Function for Summary Sheet stevefromnaki Excel Discussion (Misc queries) 2 October 16th 07 05:16 PM
VBA does not recognize Excel worksheet function "indirect" Todkerr Excel Programming 3 October 12th 05 08:51 PM
Excel VBA, won't recognize "Word.Application" object Skyron Excel Programming 2 May 19th 04 08:48 PM


All times are GMT +1. The time now is 03:15 AM.

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

About Us

"It's about Microsoft Excel"