ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   UDF in module of personal.xls (https://www.excelbanter.com/excel-discussion-misc-queries/235862-udf-module-personal-xls.html)

Jack Sons

UDF in module of personal.xls
 
Hi all,

When I put a UDF in a module of the workbook in which I want to use the UDF
the result is #NAME?
When I put a UDF in a module of personal.xls I can use it in any other xls,
I thought. But when I do, the result also is #NAME?
Strange enough, UDF's that I put in modules of workbooks or personal.xls
long ago do work flawlessly.

See the most recent example below.

What goes wrong and how to correct it?

TIA

Jack Sons
The Netherlands
---------------------------------------------------------------------------------------------------
'To use the macro, simply call the function with the value you want to find
'(say cell C1), the range whose first column should be searched
'(such as A:B), and optionally the offset of the column within that range,
as he
'=CaseVLook(C1;A:B;2) semicolons because of my European version of Excel
2000.


Function CaseVLook(compare_value, table_array As Range, _
Optional col_index As Integer = 1)
Dim c As Range
Dim rngColumn1 As Range

Application.Volatile

Set rngColumn1 = table_array.Columns(1)
CaseVLook = "Not Found"

'Loop first column
For Each c In rngColumn1.Cells
If c.Value = compare_value Then
CaseVLook = c.Offset(0, col_index - 1).Value
Exit For
End If
Next c
End Function



Mike H

UDF in module of personal.xls
 
Hi,

You need to tell Excel it's in Personal.Xls

Application.Run "Personal.xls!CaseVLook............etc

Mike

"Jack Sons" wrote:

Hi all,

When I put a UDF in a module of the workbook in which I want to use the UDF
the result is #NAME?
When I put a UDF in a module of personal.xls I can use it in any other xls,
I thought. But when I do, the result also is #NAME?
Strange enough, UDF's that I put in modules of workbooks or personal.xls
long ago do work flawlessly.

See the most recent example below.

What goes wrong and how to correct it?

TIA

Jack Sons
The Netherlands
---------------------------------------------------------------------------------------------------
'To use the macro, simply call the function with the value you want to find
'(say cell C1), the range whose first column should be searched
'(such as A:B), and optionally the offset of the column within that range,
as he
'=CaseVLook(C1;A:B;2) semicolons because of my European version of Excel
2000.


Function CaseVLook(compare_value, table_array As Range, _
Optional col_index As Integer = 1)
Dim c As Range
Dim rngColumn1 As Range

Application.Volatile

Set rngColumn1 = table_array.Columns(1)
CaseVLook = "Not Found"

'Loop first column
For Each c In rngColumn1.Cells
If c.Value = compare_value Then
CaseVLook = c.Offset(0, col_index - 1).Value
Exit For
End If
Next c
End Function




Ron de Bruin

UDF in module of personal.xls
 
Or set a reference

Go to ToolsReferences in the VBA editor with the workbook selected in the project window and
add a check mark before your Personal project. (Save the workbook then)

See the funcction exmple on this page
http://www.rondebruin.nl/personal.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Mike H" wrote in message ...
Hi,

You need to tell Excel it's in Personal.Xls

Application.Run "Personal.xls!CaseVLook............etc

Mike

"Jack Sons" wrote:

Hi all,

When I put a UDF in a module of the workbook in which I want to use the UDF
the result is #NAME?
When I put a UDF in a module of personal.xls I can use it in any other xls,
I thought. But when I do, the result also is #NAME?
Strange enough, UDF's that I put in modules of workbooks or personal.xls
long ago do work flawlessly.

See the most recent example below.

What goes wrong and how to correct it?

TIA

Jack Sons
The Netherlands
---------------------------------------------------------------------------------------------------
'To use the macro, simply call the function with the value you want to find
'(say cell C1), the range whose first column should be searched
'(such as A:B), and optionally the offset of the column within that range,
as he
'=CaseVLook(C1;A:B;2) semicolons because of my European version of Excel
2000.


Function CaseVLook(compare_value, table_array As Range, _
Optional col_index As Integer = 1)
Dim c As Range
Dim rngColumn1 As Range

Application.Volatile

Set rngColumn1 = table_array.Columns(1)
CaseVLook = "Not Found"

'Loop first column
For Each c In rngColumn1.Cells
If c.Value = compare_value Then
CaseVLook = c.Offset(0, col_index - 1).Value
Exit For
End If
Next c
End Function




Gord Dibben

UDF in module of personal.xls
 
For a UDF

=Personal.xls!CaseVlook(args)


Gord Dibben MS Excel MVP

On Sun, 5 Jul 2009 02:58:00 -0700, Mike H
wrote:

Hi,

You need to tell Excel it's in Personal.Xls

Application.Run "Personal.xls!CaseVLook............etc

Mike

"Jack Sons" wrote:

Hi all,

When I put a UDF in a module of the workbook in which I want to use the UDF
the result is #NAME?
When I put a UDF in a module of personal.xls I can use it in any other xls,
I thought. But when I do, the result also is #NAME?
Strange enough, UDF's that I put in modules of workbooks or personal.xls
long ago do work flawlessly.

See the most recent example below.

What goes wrong and how to correct it?

TIA

Jack Sons
The Netherlands
---------------------------------------------------------------------------------------------------
'To use the macro, simply call the function with the value you want to find
'(say cell C1), the range whose first column should be searched
'(such as A:B), and optionally the offset of the column within that range,
as he
'=CaseVLook(C1;A:B;2) semicolons because of my European version of Excel
2000.


Function CaseVLook(compare_value, table_array As Range, _
Optional col_index As Integer = 1)
Dim c As Range
Dim rngColumn1 As Range

Application.Volatile

Set rngColumn1 = table_array.Columns(1)
CaseVLook = "Not Found"

'Loop first column
For Each c In rngColumn1.Cells
If c.Value = compare_value Then
CaseVLook = c.Offset(0, col_index - 1).Value
Exit For
End If
Next c
End Function






All times are GMT +1. The time now is 10:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com