Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Range as variable No.2

Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup worksheet
function with my own function declarated below. In this
function I use "rng" and rng1 as Range variable, and I
would like to change the values in the range's first
column before working with it. (That's and others why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only I rem
the " 'rng1.Range("a1").Value = 2 " line.



Function fkeres1(ByVal cella, rng As Range, Optional i As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i, logikai)
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range as variable No.2

A function used in a worksheet can only return a value to the cell in which
it is used. It can not alter the excel environment, such as changing values
in other cells or formatting in any cell as examples.

--
Regards,
Tom Ogilvy
"Zsola" wrote in message
...
Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup worksheet
function with my own function declarated below. In this
function I use "rng" and rng1 as Range variable, and I
would like to change the values in the range's first
column before working with it. (That's and others why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only I rem
the " 'rng1.Range("a1").Value = 2 " line.



Function fkeres1(ByVal cella, rng As Range, Optional i As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i, logikai)
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Range as variable No.2

Thank you for your answer!

I note, that the function works as a worksheet function in
this form, but if I remove the " ' " (without this it
won't work).
The main questonaire is, how can I use this function with
changed values in the range given as parameter.

Thanks in advance.


-----Original Message-----
A function used in a worksheet can only return a value to

the cell in which
it is used. It can not alter the excel environment, such

as changing values
in other cells or formatting in any cell as examples.

--
Regards,
Tom Ogilvy
"Zsola" wrote in message
...
Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup worksheet
function with my own function declarated below. In this
function I use "rng" and rng1 as Range variable, and I
would like to change the values in the range's first
column before working with it. (That's and others why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only I

rem
the " 'rng1.Range("a1").Value = 2 " line.



Function fkeres1(ByVal cella, rng As Range, Optional i

As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i,

logikai)
End Function



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range as variable No.2

I believe, that within your function, you would have to put the values of
the rng in an array and use the array as the second argument to Vlookup. In
xl2000 and earlier, I believe the number of cells in the range will not be
able to exceed 5461.

--
Regards,
Tom Ogilvy

"Zsola" wrote in message
...
Thank you for your answer!

I note, that the function works as a worksheet function in
this form, but if I remove the " ' " (without this it
won't work).
The main questonaire is, how can I use this function with
changed values in the range given as parameter.

Thanks in advance.


-----Original Message-----
A function used in a worksheet can only return a value to

the cell in which
it is used. It can not alter the excel environment, such

as changing values
in other cells or formatting in any cell as examples.

--
Regards,
Tom Ogilvy
"Zsola" wrote in message
...
Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup worksheet
function with my own function declarated below. In this
function I use "rng" and rng1 as Range variable, and I
would like to change the values in the range's first
column before working with it. (That's and others why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only I

rem
the " 'rng1.Range("a1").Value = 2 " line.



Function fkeres1(ByVal cella, rng As Range, Optional i

As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i,

logikai)
End Function



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Range as variable No.2

Thank you Tom!

I'm not an expert... and how about putting range values
into arrays?

Thanks



-----Original Message-----
I believe, that within your function, you would have to

put the values of
the rng in an array and use the array as the second

argument to Vlookup. In
xl2000 and earlier, I believe the number of cells in the

range will not be
able to exceed 5461.

--
Regards,
Tom Ogilvy

"Zsola" wrote in

message
...
Thank you for your answer!

I note, that the function works as a worksheet

function in
this form, but if I remove the " ' " (without this it
won't work).
The main questonaire is, how can I use this function

with
changed values in the range given as parameter.

Thanks in advance.


-----Original Message-----
A function used in a worksheet can only return a

value to
the cell in which
it is used. It can not alter the excel environment,

such
as changing values
in other cells or formatting in any cell as examples.

--
Regards,
Tom Ogilvy
"Zsola" wrote in message
...
Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup

worksheet
function with my own function declarated below. In

this
function I use "rng" and rng1 as Range variable,

and I
would like to change the values in the range's first
column before working with it. (That's and others

why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only

I
rem
the " 'rng1.Range("a1").Value = 2 " line.



Function fkeres1(ByVal cella, rng As Range,

Optional i
As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i,

logikai)
End Function



.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Range as variable No.2

This might be too specific if you really were just showing an example:

Option Explicit
Function fkeres1(ByVal cella, rng As Range, _
Optional i As Long = 2, _
Optional logikai As Boolean = False)

If cella = 2 Then
fkeres1 = rng(1).Offset(0, i - 1).Value
Else
fkeres1 = Application.VLookup(cella, rng, i, logikai)
End If

End Function

(Application.vlookup handles no match (#n/a's) nicer than
worksheetfunction.vlookup.)






Zsola wrote:

Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup worksheet
function with my own function declarated below. In this
function I use "rng" and rng1 as Range variable, and I
would like to change the values in the range's first
column before working with it. (That's and others why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only I rem
the " 'rng1.Range("a1").Value = 2 " line.

Function fkeres1(ByVal cella, rng As Range, Optional i As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i, logikai)
End Function


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Range as variable No.2

Maybe something like this:

Option Explicit
Function fkeres1(ByVal cella, rng As Range, _
Optional i As Long = 2, _
Optional logikai As Boolean = False)

Dim myArr As Variant
myArr = rng.Value
myArr(1, 1) = 2
fkeres1 = Application.VLookup(cella, myArr, i, logikai)

End Function



Zsola wrote:

Thank you Tom!

I'm not an expert... and how about putting range values
into arrays?

Thanks

-----Original Message-----
I believe, that within your function, you would have to

put the values of
the rng in an array and use the array as the second

argument to Vlookup. In
xl2000 and earlier, I believe the number of cells in the

range will not be
able to exceed 5461.

--
Regards,
Tom Ogilvy

"Zsola" wrote in

message
...
Thank you for your answer!

I note, that the function works as a worksheet

function in
this form, but if I remove the " ' " (without this it
won't work).
The main questonaire is, how can I use this function

with
changed values in the range given as parameter.

Thanks in advance.


-----Original Message-----
A function used in a worksheet can only return a

value to
the cell in which
it is used. It can not alter the excel environment,

such
as changing values
in other cells or formatting in any cell as examples.

--
Regards,
Tom Ogilvy
"Zsola" wrote in message
...
Hi All,

I'm working in excel97 VBA.
My aim is to "override" the original VLookup

worksheet
function with my own function declarated below. In

this
function I use "rng" and rng1 as Range variable,

and I
would like to change the values in the range's first
column before working with it. (That's and others

why
using new variable rng1 as Range.)

I can't explain, why doesn't it work at all if only

I
rem
the " 'rng1.Range("a1").Value = 2 " line.



Function fkeres1(ByVal cella, rng As Range,

Optional i
As
Long = 2, Optional logikai As Boolean = False)
Dim rng1 As Range

Set rng1 = rng
'rng1.Range("a1").Value = 2

fkeres1 = WorksheetFunction.VLookup(cella, rng, i,
logikai)
End Function



.



.


--

Dave Peterson
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
Variable Range James C. Excel Discussion (Misc queries) 3 April 2nd 09 12:41 AM
from Range variable Marina Limeira Excel Discussion (Misc queries) 0 January 22nd 06 02:35 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Variable Range Martin[_9_] Excel Programming 1 October 12th 03 05:09 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 05:15 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"