Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Loading a formula from VB

I am attempting to load a formula from VB. I get an object defined error on
the final line of code below

Dim formula_str As String

Range(M4).Select

formula_str =
"=IF(ISERROR(VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE)),0,VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE))"
ActiveCell.FormulaR1C1 = formula_str

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loading a formula from VB

Without testing...

You wrote your formula in A1 reference style--not R1C1 reference style.

ActiveCell.Formula = formula_str





Michael wrote:

I am attempting to load a formula from VB. I get an object defined error on
the final line of code below

Dim formula_str As String

Range(M4).Select

formula_str =
"=IF(ISERROR(VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE)),0,VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE))"
ActiveCell.FormulaR1C1 = formula_str


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Loading a formula from VB

I already tried the R1C1 style. That does not work either. It appears that
I will have to break the formula into two and use different columns.

"Dave Peterson" wrote:

Without testing...

You wrote your formula in A1 reference style--not R1C1 reference style.

ActiveCell.Formula = formula_str





Michael wrote:

I am attempting to load a formula from VB. I get an object defined error on
the final line of code below

Dim formula_str As String

Range(M4).Select

formula_str =
"=IF(ISERROR(VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE)),0,VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE))"
ActiveCell.FormulaR1C1 = formula_str


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loading a formula from VB

Maybe you should paste a copy of your code from the code window instead of
retyping it into the post.

This line failed for me:
Range(M4).Select
It should be
Range("M4").Select

But your formula worked ok for me if I had a workbook named filename.xls open
and changed the line to:

ActiveCell.Formula = formula_str




Michael wrote:

I already tried the R1C1 style. That does not work either. It appears that
I will have to break the formula into two and use different columns.

"Dave Peterson" wrote:

Without testing...

You wrote your formula in A1 reference style--not R1C1 reference style.

ActiveCell.Formula = formula_str





Michael wrote:

I am attempting to load a formula from VB. I get an object defined error on
the final line of code below

Dim formula_str As String

Range(M4).Select

formula_str =
"=IF(ISERROR(VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE)),0,VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE))"
ActiveCell.FormulaR1C1 = formula_str


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Loading a formula from VB

Sorry - The M4 "M4" was a typo. I have a variable in my actual code but did
not want to confuse the issue here.

Removing the R1C1 from the ActiveCell.Formula line worked.

Thank You

"Dave Peterson" wrote:

Maybe you should paste a copy of your code from the code window instead of
retyping it into the post.

This line failed for me:
Range(M4).Select
It should be
Range("M4").Select

But your formula worked ok for me if I had a workbook named filename.xls open
and changed the line to:

ActiveCell.Formula = formula_str




Michael wrote:

I already tried the R1C1 style. That does not work either. It appears that
I will have to break the formula into two and use different columns.

"Dave Peterson" wrote:

Without testing...

You wrote your formula in A1 reference style--not R1C1 reference style.

ActiveCell.Formula = formula_str





Michael wrote:

I am attempting to load a formula from VB. I get an object defined error on
the final line of code below

Dim formula_str As String

Range(M4).Select

formula_str =
"=IF(ISERROR(VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE)),0,VLOOKUP(A4,'[filename.xls]sheet1'!$A$2:$B$100,2,FALSE))"
ActiveCell.FormulaR1C1 = formula_str

--

Dave Peterson


--

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
loading mallahd Excel Discussion (Misc queries) 2 May 25th 07 07:59 PM
add-ins not loading BigJimmer Excel Programming 1 March 2nd 07 05:13 PM
Loading an xml Mike Archer Excel Programming 3 May 16th 06 07:21 AM
Loading Bar Justin Philips Excel Programming 5 March 11th 06 04:58 PM
Loading Bar rebel1970[_3_] Excel Programming 1 June 22nd 04 10:21 AM


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