Formula Syntax Problem

  • Thread starter Thread starter Bob Zimski
  • Start date Start date
B

Bob Zimski

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
 
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.
 
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' :)
 
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.
 
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).
 
Back
Top