Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Macro Query -

Hi I have this small query.


I have written the macro (my first!) as below
Function FindOldNominal(NomCode)

FindOldNominal = WorksheetFunction.VLookup(NomCode,
range("IMPORTRANGE"),5,false)
End Function




This works fine... except..


If I alter the value in the defined range "ImportRange" say from 10 to 20
at nomcode X then

FindOldNominal(X) still says 10, unless I go into the cell where the
formula call of '=FindOldNominal(X)' is and press enter again.

My question is I would like it to update it self automatically like the
sum
function "=sum" does. Is there a reason why this macro isn't or are all
macros like this.
Is there a way round it if this is the case.


Many thanks in anticipation

James


Bob wrote in reponse (BUT IS THIS IS THE ONLY OPTION -i want to try
and keep the formula as simple as possible
other people will be using it)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Macro Query -

Hi James:

You should pass the lookup table to the function as a parameter, e.g:

'=============
Function FindOldNominal(NomCode, Table As Range)
FindOldNominal = WorksheetFunction. _
VLookup(NomCode, Table, 2, False)
End Function
'<<=============

Alternatively, and very much as a second best option, Insert the line:

Application.Volatile

at the head of your function. This will ensure that the function will update
every time that the worksheet is recalculated.



---
Regards,
Norman



"James Cornthwaite" wrote in message
...
Hi I have this small query.


I have written the macro (my first!) as below
Function FindOldNominal(NomCode)

FindOldNominal = WorksheetFunction.VLookup(NomCode,
range("IMPORTRANGE"),5,false)
End Function




This works fine... except..


If I alter the value in the defined range "ImportRange" say from 10 to 20
at nomcode X then

FindOldNominal(X) still says 10, unless I go into the cell where the
formula call of '=FindOldNominal(X)' is and press enter again.

My question is I would like it to update it self automatically like the
sum
function "=sum" does. Is there a reason why this macro isn't or are all
macros like this.
Is there a way round it if this is the case.


Many thanks in anticipation

James


Bob wrote in reponse (BUT IS THIS IS THE ONLY OPTION -i want to try
and keep the formula as simple as possible
other people will be using it)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Macro Query -

or just use:

FindOldNominal = Application.WorksheetFunction.VLookup(NomCode,
range("IMPORTRANGE"),5,false)

all the best
Jason

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Macro Query -

thats great thanks

"WhytheQ" wrote in message
oups.com...
or just use:

FindOldNominal = Application.WorksheetFunction.VLookup(NomCode,
range("IMPORTRANGE"),5,false)

all the best
Jason



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro Query -

or just use:
FindOldNominal = Application.WorksheetFunction.VLookup(NomCode,
range("IMPORTRANGE"),5,false)




What's great about it? Could you clarify.

I don't see any difference from what you had - adding Application adds
nothing? Are you saying that makes the formula update for a change in the
lookup range?
It certainly didn't for me.
--
Regards,
Tom Ogilvy

"James Cornthwaite" wrote in message
...
thats great thanks

"WhytheQ" wrote in message
oups.com...
or just use:

FindOldNominal = Application.WorksheetFunction.VLookup(NomCode,
range("IMPORTRANGE"),5,false)

all the best
Jason





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
Macro Query carla 7 Excel Discussion (Misc queries) 5 July 31st 08 04:07 PM
another macro query - deleting a worksheet within a query DavidHawes Excel Discussion (Misc queries) 2 February 26th 07 10:05 AM
New Web Query Macro A.J Excel Programming 1 July 24th 05 05:06 AM
NEW WEB QUERY MACRO A.J Setting up and Configuration of Excel 0 July 24th 05 04:31 AM
Query during macro run mkingsley[_2_] Excel Programming 3 May 25th 04 04:15 PM


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