Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Formula problem once inserted by VBA

I have the following line which inserts a vlookup formula into a cell,
drops down to the next cell does the same in a loop....

ActiveCell.Formula = "=VLOOKUP(RC[-1],Delivery!B:D,2,false)"

However, all I get is a #NAME? error, but if I click on the cell to
edit it and hit return the formula magically works! How do I get the
formula to work without having to go into every cell once I've run my
macro?

Also, if I type the vlookup into another cell
=vlookup(A2,Delivery!B:D,2,false) and go between the cells the formula
is EXACTLY the same, yet one (the manually entered one) works and the
other (entered by macro) doesn't until I've entered it and hit
return......

I'm stumped.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Formula problem once inserted by VBA

You have a mixture of the 2 reference styles: R1C1 and A1
Probably easiest to change the RC[-1] to A1

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


wrote in message ups.com...
|I have the following line which inserts a vlookup formula into a cell,
| drops down to the next cell does the same in a loop....
|
| ActiveCell.Formula = "=VLOOKUP(RC[-1],Delivery!B:D,2,false)"
|
| However, all I get is a #NAME? error, but if I click on the cell to
| edit it and hit return the formula magically works! How do I get the
| formula to work without having to go into every cell once I've run my
| macro?
|
| Also, if I type the vlookup into another cell
| =vlookup(A2,Delivery!B:D,2,false) and go between the cells the formula
| is EXACTLY the same, yet one (the manually entered one) works and the
| other (entered by macro) doesn't until I've entered it and hit
| return......
|
| I'm stumped.
|
| Thanks
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formula problem once inserted by VBA

Since your formula relies on the activecell, it would make it easier to
translate your rc[-1] if you shared the activecell's location. Niek guessed
that the formula was going into B1 (so rc[-1] refereed to A1.

Another option would be:

ActiveCell.Formular1c1 = "=VLOOKUP(RC[-1],Delivery!c2:c4,2,false)"

Since this uses .formular1c1, delivery!c2:c4 refers to Column 2 to Column 4 in
R1C1 notation (same as B:D).





wrote:

I have the following line which inserts a vlookup formula into a cell,
drops down to the next cell does the same in a loop....

ActiveCell.Formula = "=VLOOKUP(RC[-1],Delivery!B:D,2,false)"

However, all I get is a #NAME? error, but if I click on the cell to
edit it and hit return the formula magically works! How do I get the
formula to work without having to go into every cell once I've run my
macro?

Also, if I type the vlookup into another cell
=vlookup(A2,Delivery!B:D,2,false) and go between the cells the formula
is EXACTLY the same, yet one (the manually entered one) works and the
other (entered by macro) doesn't until I've entered it and hit
return......

I'm stumped.

Thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formula problem once inserted by VBA

(so rc[-1] referred to A1).

There were no referees harmed in the making of that post!

Dave Peterson wrote:

Since your formula relies on the activecell, it would make it easier to
translate your rc[-1] if you shared the activecell's location. Niek guessed
that the formula was going into B1 (so rc[-1] refereed to A1.

Another option would be:

ActiveCell.Formular1c1 = "=VLOOKUP(RC[-1],Delivery!c2:c4,2,false)"

Since this uses .formular1c1, delivery!c2:c4 refers to Column 2 to Column 4 in
R1C1 notation (same as B:D).

wrote:

I have the following line which inserts a vlookup formula into a cell,
drops down to the next cell does the same in a loop....

ActiveCell.Formula = "=VLOOKUP(RC[-1],Delivery!B:D,2,false)"

However, all I get is a #NAME? error, but if I click on the cell to
edit it and hit return the formula magically works! How do I get the
formula to work without having to go into every cell once I've run my
macro?

Also, if I type the vlookup into another cell
=vlookup(A2,Delivery!B:D,2,false) and go between the cells the formula
is EXACTLY the same, yet one (the manually entered one) works and the
other (entered by macro) doesn't until I've entered it and hit
return......

I'm stumped.

Thanks


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Formula problem once inserted by VBA

I changed it to ActiveCell.Formular1c1 =
"=VLOOKUP(RC[-1],Delivery!c2:c4,2,false)"


and it worked grand. Thank you so much!



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
How to fix a formula, so when a row is inserted it doesn't cha Paul Cahoon Excel Discussion (Misc queries) 4 December 9th 08 09:50 PM
Repeat formula with inserted row Fred Excel Worksheet Functions 3 November 6th 08 09:04 AM
How to fix a formula, so when a row is inserted it doesn't cha futureplus Excel Discussion (Misc queries) 1 August 12th 08 03:44 AM
How do I continue a formula in an inserted row? jess Excel Discussion (Misc queries) 0 May 19th 05 09:21 PM
VLookup problem when a new row has been inserted jessica Excel Programming 2 February 10th 05 05:55 PM


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

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"