Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Insert Formula

In one field I have an change module that, amound other
things sets the value of a field in my spreadsheet if
certain conditions exist to a vlookup formula. The line of
code is as follows:

Worksheets(1).Range("C2").Formula = "=if(B2="" , "",VLOOKUP
(B2,Z2:AA9,2))"

What ends up in the cell is the following:

=IF(B2=" , ",VLOOKUP(B2,Z2:AA9,2))

which evaluates to false instead of doing what I need and
retrieving the desired value.

The insert worked correctly until I addded the if
statement. I have validation built in to prevent a null or
empty value in the lookup cell but I needed to handdle it
initially in case the user had not actually chosen a
value.

Any help would be greatly appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Insert Formula

Hi Kevin,

If u write a formula in the code then if u have a single quote in the
formula then put double quotes in the code, if u have double quotes then put
4 and so on.

So your formula shud read as
Worksheets(1).Range("C2").Formula = "=if(B2="""" ,
"""",VLOOKUP(B2,Z2:AA9,2))"

Regards,
Hari
India

"Kevin" wrote in message
...
In one field I have an change module that, amound other
things sets the value of a field in my spreadsheet if
certain conditions exist to a vlookup formula. The line of
code is as follows:

Worksheets(1).Range("C2").Formula = "=if(B2="" , "",VLOOKUP
(B2,Z2:AA9,2))"

What ends up in the cell is the following:

=IF(B2=" , ",VLOOKUP(B2,Z2:AA9,2))

which evaluates to false instead of doing what I need and
retrieving the desired value.

The insert worked correctly until I addded the if
statement. I have validation built in to prevent a null or
empty value in the lookup cell but I needed to handdle it
initially in case the user had not actually chosen a
value.

Any help would be greatly appreciated!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Insert Formula

Hi
try:
Worksheets(1).Range("C2").Formula = "=if(B2="""","""",VLOOKUP
(B2,Z2:AA9,2))"

--
Regards
Frank Kabel
Frankfurt, Germany


Kevin wrote:
In one field I have an change module that, amound other
things sets the value of a field in my spreadsheet if
certain conditions exist to a vlookup formula. The line of
code is as follows:

Worksheets(1).Range("C2").Formula = "=if(B2="" , "",VLOOKUP
(B2,Z2:AA9,2))"

What ends up in the cell is the following:

=IF(B2=" , ",VLOOKUP(B2,Z2:AA9,2))

which evaluates to false instead of doing what I need and
retrieving the desired value.

The insert worked correctly until I addded the if
statement. I have validation built in to prevent a null or
empty value in the lookup cell but I needed to handdle it
initially in case the user had not actually chosen a
value.

Any help would be greatly appreciated!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Insert Formula

Thankyou one and all!
-----Original Message-----
In one field I have an change module that, amound other
things sets the value of a field in my spreadsheet if
certain conditions exist to a vlookup formula. The line

of
code is as follows:

Worksheets(1).Range("C2").Formula = "=if

(B2="" , "",VLOOKUP
(B2,Z2:AA9,2))"

What ends up in the cell is the following:

=IF(B2=" , ",VLOOKUP(B2,Z2:AA9,2))

which evaluates to false instead of doing what I need and
retrieving the desired value.

The insert worked correctly until I addded the if
statement. I have validation built in to prevent a null

or
empty value in the lookup cell but I needed to handdle it
initially in case the user had not actually chosen a
value.

Any help would be greatly appreciated!
.

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
Insert Row with formula RKS Excel Discussion (Misc queries) 1 April 10th 08 12:09 PM
insert formula [email protected] Excel Worksheet Functions 0 May 17th 06 12:45 PM
How to insert a formula..but... junkmandan Excel Discussion (Misc queries) 6 January 26th 06 08:17 PM
How to insert = in formula bar Tirtha Raj Adhikari Excel Discussion (Misc queries) 1 September 14th 05 09:02 AM
insert a new row by formula Doug Excel Worksheet Functions 3 November 18th 04 12:28 PM


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