PC Review


Reply
Thread Tools Rate Thread

Conflict in assigning values to a cell from another cell

 
 
=?Utf-8?B?am9lZA==?=
Guest
Posts: n/a
 
      20th Aug 2007
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 ??

--
j.f.dolan
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      20th Aug 2007
Try formatting B16 as General and see if you still get the type mismatch.

"joed" wrote:

> 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 ??
>
> --
> j.f.dolan

 
Reply With Quote
 
=?Utf-8?B?am9lZA==?=
Guest
Posts: n/a
 
      20th Aug 2007
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.
--
j.f.dolan


"JLGWhiz" wrote:

> Try formatting B16 as General and see if you still get the type mismatch.
>
> "joed" wrote:
>
> > 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 ??
> >
> > --
> > j.f.dolan

 
Reply With Quote
 
=?Utf-8?B?am9lZA==?=
Guest
Posts: n/a
 
      21st Aug 2007
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.
--
j.f.dolan


"JLGWhiz" wrote:

> Try formatting B16 as General and see if you still get the type mismatch.
>
> "joed" wrote:
>
> > 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 ??
> >
> > --
> > j.f.dolan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning cell values to variables Tim Microsoft Excel Misc 3 11th Jun 2009 04:30 PM
Assigning cell values with VB cathywoodford@personainternet.com Microsoft Excel Programming 3 15th Feb 2008 01:51 PM
Assigning cell values within a VBA program =?Utf-8?B?Q2hyaXMgQnVycm93cw==?= Microsoft Excel Programming 2 6th Apr 2004 11:31 PM
assigning cell values in formulas M Microsoft Excel Programming 10 31st Dec 2003 12:02 AM
assigning cell values to variables Ruune Microsoft Excel Worksheet Functions 1 3rd Dec 2003 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 AM.