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

Hello all. I'm having a problem trying to place a variable in a
formula. I'm using Excel 2000. I am using the Exact formula to
compare two text strings. Both strings are variables, and one string
needs quotes around it for Excel to evaluate the formula properly.
The quotes are where I'm hanging up. Here is an example of my code:

AnVar1 = "" & AnVar & ""
Range("IV1").Formula = "=EXACT(" & AnVar1 & "," & ActiveCell.Address &
")"

AnVar is something like Ag, or Al, etc. AnVar1 sets the string
correctly so it reads: "Ag" or "Al". When this is passed to the
formula the quotes are not included. So, in Excel in cell IV1 the
formula is: =Exact(Ag,"B1"). Since there no quotes around the Ag text
the formula errors out.

I've tried various ways to get the quotes included like using double
quotes, plus signs, and & signs. These usually produce either errors
or passes straight variable text to the formula.

I would appreciate any help on this problem.

Thanks,
Amy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Variable in a Formula

Amy,

You need to enclose the value of AnVar1 within quotes, and when
you need to use literal quotes in a VBA string, you use two of
the "". So your code would look like the following:

Range("IV1").Formula = "=EXACT(""" & AnVar1 & """," & _
ActiveCell.Address & ")"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Amy Ja" wrote in message
om...
Hello all. I'm having a problem trying to place a variable in

a
formula. I'm using Excel 2000. I am using the Exact formula

to
compare two text strings. Both strings are variables, and one

string
needs quotes around it for Excel to evaluate the formula

properly.
The quotes are where I'm hanging up. Here is an example of my

code:

AnVar1 = "" & AnVar & ""
Range("IV1").Formula = "=EXACT(" & AnVar1 & "," &

ActiveCell.Address &
")"

AnVar is something like Ag, or Al, etc. AnVar1 sets the string
correctly so it reads: "Ag" or "Al". When this is passed to

the
formula the quotes are not included. So, in Excel in cell IV1

the
formula is: =Exact(Ag,"B1"). Since there no quotes around the

Ag text
the formula errors out.

I've tried various ways to get the quotes included like using

double
quotes, plus signs, and & signs. These usually produce either

errors
or passes straight variable text to the formula.

I would appreciate any help on this problem.

Thanks,
Amy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variable in a Formula

Chip - Thanks so much! That did it. Now I can quit tearing my hair
out. :)

Thanks,
Amy


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Variable in a Formula

Hi
try
Range("IV1").Formula = "=EXACT(" & "" & AnVar1 & "" & "," &
ActiveCell.Address &")"


--
Regards
Frank Kabel
Frankfurt, Germany

"Amy Ja" schrieb im Newsbeitrag
om...
Hello all. I'm having a problem trying to place a variable in a
formula. I'm using Excel 2000. I am using the Exact formula to
compare two text strings. Both strings are variables, and one string
needs quotes around it for Excel to evaluate the formula properly.
The quotes are where I'm hanging up. Here is an example of my code:

AnVar1 = "" & AnVar & ""
Range("IV1").Formula = "=EXACT(" & AnVar1 & "," & ActiveCell.Address

&
")"

AnVar is something like Ag, or Al, etc. AnVar1 sets the string
correctly so it reads: "Ag" or "Al". When this is passed to the
formula the quotes are not included. So, in Excel in cell IV1 the
formula is: =Exact(Ag,"B1"). Since there no quotes around the Ag

text
the formula errors out.

I've tried various ways to get the quotes included like using double
quotes, plus signs, and & signs. These usually produce either errors
or passes straight variable text to the formula.

I would appreciate any help on this problem.

Thanks,
Amy


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
Variable VBA Max Formula Gizmo Excel Discussion (Misc queries) 2 June 6th 08 06:12 AM
DDE formula with variable Bruce Excel Worksheet Functions 0 November 16th 07 09:03 AM
Using a variable in a VBA formula Colin Vicary Excel Discussion (Misc queries) 3 November 8th 05 11:39 AM
Formula Variable Ronbo Excel Programming 3 March 4th 04 09:33 PM
Variable to formula. russell \(skmr3\) Excel Programming 1 July 30th 03 07:11 AM


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