Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default writing formula w/ variables

This should be a simple solution but I can't figure it out... Here is
the line of code I'm having issues with -

.Formula = "=(((COUNT(b:b)+" & var1 & ")*5)-SUM(b:c))/" & var1 &"

Why isn't this working for me? I used the same basic "& _ &" roadmap
in the following code with no problem

Range("H7").Value = "In " & var1 & " Days:"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default writing formula w/ variables

On Jun 30, 1:24*pm, Matthew Dyer wrote:
This should be a simple solution but I can't figure it out... Here is
the line of code I'm having issues with -

* * .Formula = "=(((COUNT(b:b)+" & var1 & ")*5)-SUM(b:c))/" & var1 &"

Why isn't this working for me? I used the same basic "& _ &" roadmap
in the following code with no problem

Range("H7").Value = "In " & var1 & " Days:"


I used a workaround where I just put the value of var1 in a cell and
referanced the cell instead of the variable, but I would definatley
appreciate anyone who could tell me what I'm doing wrong... Thanks!!!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default writing formula w/ variables

On Jun 30, 6:38*pm, Matthew Dyer wrote:
On Jun 30, 1:24*pm, Matthew Dyer wrote:

This should be a simple solution but I can't figure it out... Here is
the line of code I'm having issues with -


* * .Formula = "=(((COUNT(b:b)+" & var1 & ")*5)-SUM(b:c))/" & var1 &"


Why isn't this working for me? I used the same basic "& _ &" roadmap
in the following code with no problem


Range("H7").Value = "In " & var1 & " Days:"


I used a workaround where I just put the value of var1 in a cell and
referanced the cell instead of the variable, but I would definatley
appreciate anyone who could tell me what I'm doing wrong... Thanks!!!


Try your formula on the worksheetput an apostophe in frontcopy to vb
editormodidy
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default writing formula w/ variables

On 30 June, 16:24, Matthew Dyer wrote:
This should be a simple solution but I can't figure it out... Here is
the line of code I'm having issues with -

* * .Formula = "=(((COUNT(b:b)+" & var1 & ")*5)-SUM(b:c))/" & var1 &"

Why isn't this working for me? I used the same basic "& _ &" roadmap
in the following code with no problem

Range("H7").Value = "In " & var1 & " Days:"


hi
i noticed in your formula that the ampersand symbol(&) is WITHIN the
double quotes. this makes it text along with var1.
the ampersand symbol should ALWAYS be OUTSIDE of the double quotes ie
..Formula = "=(((COUNT(b:b) +" & var1 & ")*5)-SUM(b:c) )/ " & var1
the above is tested in 03 and works.
also I noticed that in your second example, the ampersands are
OUTSIDE of the double quotes as is var1.
if you have trouble understanding this, look at it this way....
Range("H7").Value = "Inside " & outside & " inside:"
the ampersands concatenates all of the text(numbers,other) between the
multiple double quotes.
anything WITHIN the double quotes is taken literally by excel(VB).
anything OUTSIDE the double quotes are declared variables. (you did
declare them and assign values, didn't you)

regards
FSt1
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default writing formula w/ variables

On Jun 30, 3:24*pm, Matthew Dyer wrote:
This should be a simple solution but I can't figure it out... Here is
the line of code I'm having issues with -

* * .Formula = "=(((COUNT(b:b)+" & var1 & ")*5)-SUM(b:c))/" & var1 &"

Why isn't this working for me? I used the same basic "& _ &" roadmap
in the following code with no problem

Range("H7").Value = "In " & var1 & " Days:"


Well, stubbed in this code

Dim rnga As Range, var1 As Double
Set rnga = Range("A1")
var1 = 8
With rnga
.Formula = "=(((COUNT(b:b)+" & var1 & ")*5)-SUM(b:c))/" & var1 & "
"
End With


and it worked fine. I did notice that Excel added another double
quote at the end. When I look at the formula it pasted into A1, I
get:
=(((COUNT(B:B)+8)*5)-SUM(B:C))/8

Perhaps you could give us a little more than one line of code.

Chris M.
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
Writing a variables value every second to a table MJKelly Excel Programming 2 April 16th 09 09:50 PM
help in writing a formula Soth Excel Worksheet Functions 4 February 2nd 07 12:22 AM
writing a formula changetires Excel Discussion (Misc queries) 1 June 27th 06 08:29 PM
Need help with writing formula please... Soth Excel Worksheet Functions 1 March 14th 06 07:03 PM
writing cells with variables from vba josh ashcraft Excel Programming 0 July 17th 03 03:32 PM


All times are GMT +1. The time now is 09:28 PM.

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"