Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default My first macro, uses Vlookup but doesnt update unless hit I enter



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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default My first macro, uses Vlookup but doesnt update unless hit I enter

A functionm needs to reference its cells if you want it to update when they
change.

Function FindOldNominal(NomCode,lookup_table as range)

FindOldNominal = WorksheetFunction.VLookup(NomCode, lookup_table,5,false)
End Function


FindNomial(10,IMPORTRANGE)


--
HTH

Bob Phillips

(replace xxxx in email address with googlemail if mailing direct)

"James Cornthwaite" wrote in message
...


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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default My first macro, uses Vlookup but doesnt update unless hit I enter

Hi Bob,

not fully sure what you mean. but to try and clarify

I have defined IMPORTRANGE as a global constant via INSERT, NAME, DEFINE and
then created a range called "IMPORTRANGE" refering to another worsksheet but
within the same workbook.

as i mentioned the function written in the macro works great on first time
entering it, it just doesnt update its return value to reflect any changes
made in the defined range, "IMPORTRANGE", without specifically prompting it
to (i.e. via pressing enter again on the cell).


Would be really greatful for any help. Not an expert with macros at all.

Thanks
James

"Bob Phillips" wrote in message
...
A functionm needs to reference its cells if you want it to update when they
change.

Function FindOldNominal(NomCode,lookup_table as range)

FindOldNominal = WorksheetFunction.VLookup(NomCode, lookup_table,5,false)
End Function


FindNomial(10,IMPORTRANGE)


--
HTH

Bob Phillips

(replace xxxx in email address with googlemail if mailing direct)

"James Cornthwaite" wrote in message
...


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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default My first macro, uses Vlookup but doesnt update unless hit I enter

I understood what IMPORTRANGE was.

As I said, it will work first time, because entering or updating a formula
forces a sheet recalculation. If you want it to recalculate when the range
is changed, you have to let Excel know that the function uses that range,
that is you have to pass it to the function as a parameter. To be able to
pass that range as a parameter, the function has to have a range argument.
That is why I added a lookup_table argument to the function declaration,
ands used that in the function rather than Range("IMPORTRANGE").

Try it and see.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"James Cornthwaite" wrote in message
...
Hi Bob,

not fully sure what you mean. but to try and clarify

I have defined IMPORTRANGE as a global constant via INSERT, NAME, DEFINE

and
then created a range called "IMPORTRANGE" refering to another worsksheet

but
within the same workbook.

as i mentioned the function written in the macro works great on first time
entering it, it just doesnt update its return value to reflect any changes
made in the defined range, "IMPORTRANGE", without specifically prompting

it
to (i.e. via pressing enter again on the cell).


Would be really greatful for any help. Not an expert with macros at all.

Thanks
James

"Bob Phillips" wrote in message
...
A functionm needs to reference its cells if you want it to update when

they
change.

Function FindOldNominal(NomCode,lookup_table as range)

FindOldNominal = WorksheetFunction.VLookup(NomCode,

lookup_table,5,false)
End Function


FindNomial(10,IMPORTRANGE)


--
HTH

Bob Phillips

(replace xxxx in email address with googlemail if mailing direct)

"James Cornthwaite" wrote in message
...


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








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
why doesnt my formula cell update automatically ? Wozza Excel Discussion (Misc queries) 7 January 6th 09 01:49 PM
Vlookup if #N/A then enter enter data in cell I4 duketter Excel Discussion (Misc queries) 3 March 11th 08 09:08 PM
My first macro, uses Vlookup but doesnt update unless hit enter James Cornthwaite Excel Worksheet Functions 1 May 24th 06 10:01 PM
Please help : Macro doesnt work on other PCs Jason Excel Programming 2 December 26th 05 09:49 AM
running a macro ina workbook that doesnt have that macro Paul Excel Programming 2 February 18th 04 01:47 AM


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