Conflict in assigning values to a cell from another cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Excel 2003 on an XP box

The following code snippet causes a mismatch error when it executes:

Range("B16").Value = Target.Value + Range("B16").Value

Now I have formatted "B16" to be of type Number, (and it is initially empty,
the watch directory says it's value is "") Target is also formatted to
be of type Number.
I pasted Range("B16").Value into the watch window along with target.value

The watch window says Range("B16").Value is of type Variant/String while
target.value is of type Variant/Double, which I'm sure is why I get the
mismatch
error. I thought perhaps since Range("B16").Value is initially empty I could
set it to 0 (zero) on start up of the worksheet. That did not fix the
problem. Why is Range("B16").Value of type Variant/String ??
 
Try formatting B16 as General and see if you still get the type mismatch.
 
Formatting as general did not do it. The watch window still displays the type
as Variant/String and it still throws the same mismatch error.
 
I got around the problem by checking to see if B16 value is currently
non-numeric which the first time the sheet is opened and populted it is. If
it is non-numeric I set it's value to 0 (zero). That changes the type of
"B16" to variant/double which gets rid of the type mismatch problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top