ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Formula Syntax Problem (https://www.excelbanter.com/excel-programming/431222-formula-syntax-problem.html)

Bob Zimski

Formula Syntax Problem
 
I would like to end up with a cell to have =10+2 as the formula. I don't just
want the value of 12 dumped into the cell. My attempt is below but I can't
figure out why it bombs.

Range("C" & cntrl - 1).Formula = "=" & Range("C" & cntr1 - 1).value & "+" &
Range("C" & ctrl1).value

Thanks
Bob

Rick Rothstein

Formula Syntax Problem
 
It looks like you are using 3 different variable names (and I'm guessing
only one has a value assigned to it). The last character in your first Range
call is a lower case "L", in the other two Range calls it is the number 1,
but in the last Range call the variable does not have the lower case "N" in
it that the other two variables have.

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
I would like to end up with a cell to have =10+2 as the formula. I don't
just
want the value of 12 dumped into the cell. My attempt is below but I can't
figure out why it bombs.

Range("C" & cntrl - 1).Formula = "=" & Range("C" & cntr1 - 1).value & "+"
&
Range("C" & ctrl1).value

Thanks
Bob



Bob Zimski

Formula Syntax Problem
 
Ouch, now that you mention it, it is a lot more visible here than in the VBA
editor window where the l and 1 are almost identical. as for the 'n', ...
been staring into the tube too long.

Thanks for the 'wake up call' :)

"Rick Rothstein" wrote:

It looks like you are using 3 different variable names (and I'm guessing
only one has a value assigned to it). The last character in your first Range
call is a lower case "L", in the other two Range calls it is the number 1,
but in the last Range call the variable does not have the lower case "N" in
it that the other two variables have.

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
I would like to end up with a cell to have =10+2 as the formula. I don't
just
want the value of 12 dumped into the cell. My attempt is below but I can't
figure out why it bombs.

Range("C" & cntrl - 1).Formula = "=" & Range("C" & cntr1 - 1).value & "+"
&
Range("C" & ctrl1).value

Thanks
Bob




Rick Rothstein

Formula Syntax Problem
 
It is just the opposite for me... I'm using Courier New in the VBA editor (I
wanted consistent character widths) and Arial in my email/news reader. In
VBA, the top of the one is slanted and the top of the lower case "L" is
horizontal... in my news reader, the two characters look identical.

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
Ouch, now that you mention it, it is a lot more visible here than in the
VBA
editor window where the l and 1 are almost identical. as for the 'n', ...
been staring into the tube too long.

Thanks for the 'wake up call' :)

"Rick Rothstein" wrote:

It looks like you are using 3 different variable names (and I'm guessing
only one has a value assigned to it). The last character in your first
Range
call is a lower case "L", in the other two Range calls it is the number
1,
but in the last Range call the variable does not have the lower case "N"
in
it that the other two variables have.

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
I would like to end up with a cell to have =10+2 as the formula. I don't
just
want the value of 12 dumped into the cell. My attempt is below but I
can't
figure out why it bombs.

Range("C" & cntrl - 1).Formula = "=" & Range("C" & cntr1 - 1).value &
"+"
&
Range("C" & ctrl1).value

Thanks
Bob





Rick Rothstein

Formula Syntax Problem
 
By the way, you should (IMHO) always declare (Dim) each variable and you
should use Option Explicit at the top of each module so that VB will alert
you (when you try to run your code) of any variable it encounters that are
not declared. This is extremely helpful in avoiding mistyped names of
variable/function/subs/objects/etc. To implement the automatic placing of
Option Explicit statements at the top of all *new* code windows (this won't
go back and add Option Explicit to code windows already populated with
code), click Tools/Options on the menu bar in the VBA editor, click the
Editor tab and put a check mark next to "Require Variable Declarations". I
would also consider removing the check mark next to "Auto Syntax Check"
(improper syntax will still be flagged in red, but you won't be forced to
correct the syntax right then and there).

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
Ouch, now that you mention it, it is a lot more visible here than in the
VBA
editor window where the l and 1 are almost identical. as for the 'n', ...
been staring into the tube too long.

Thanks for the 'wake up call' :)

"Rick Rothstein" wrote:

It looks like you are using 3 different variable names (and I'm guessing
only one has a value assigned to it). The last character in your first
Range
call is a lower case "L", in the other two Range calls it is the number
1,
but in the last Range call the variable does not have the lower case "N"
in
it that the other two variables have.

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
I would like to end up with a cell to have =10+2 as the formula. I don't
just
want the value of 12 dumped into the cell. My attempt is below but I
can't
figure out why it bombs.

Range("C" & cntrl - 1).Formula = "=" & Range("C" & cntr1 - 1).value &
"+"
&
Range("C" & ctrl1).value

Thanks
Bob





Bob Zimski

Formula Syntax Problem
 
You sold me one several points. Thanks very much.

Bob

"Rick Rothstein" wrote:

By the way, you should (IMHO) always declare (Dim) each variable and you
should use Option Explicit at the top of each module so that VB will alert
you (when you try to run your code) of any variable it encounters that are
not declared. This is extremely helpful in avoiding mistyped names of
variable/function/subs/objects/etc. To implement the automatic placing of
Option Explicit statements at the top of all *new* code windows (this won't
go back and add Option Explicit to code windows already populated with
code), click Tools/Options on the menu bar in the VBA editor, click the
Editor tab and put a check mark next to "Require Variable Declarations". I
would also consider removing the check mark next to "Auto Syntax Check"
(improper syntax will still be flagged in red, but you won't be forced to
correct the syntax right then and there).

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
Ouch, now that you mention it, it is a lot more visible here than in the
VBA
editor window where the l and 1 are almost identical. as for the 'n', ...
been staring into the tube too long.

Thanks for the 'wake up call' :)

"Rick Rothstein" wrote:

It looks like you are using 3 different variable names (and I'm guessing
only one has a value assigned to it). The last character in your first
Range
call is a lower case "L", in the other two Range calls it is the number
1,
but in the last Range call the variable does not have the lower case "N"
in
it that the other two variables have.

--
Rick (MVP - Excel)


"Bob Zimski" wrote in message
...
I would like to end up with a cell to have =10+2 as the formula. I don't
just
want the value of 12 dumped into the cell. My attempt is below but I
can't
figure out why it bombs.

Range("C" & cntrl - 1).Formula = "=" & Range("C" & cntr1 - 1).value &
"+"
&
Range("C" & ctrl1).value

Thanks
Bob






All times are GMT +1. The time now is 12:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com