Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Is really the default property consistently returned/assigned?

I wrote a procedure a bit like this:

For Each rngCell in rngEmployees
lstEmployees.Additem rngCell
Next rngCell

rngEmployees is a one-column range filled with employee's names.

This code is trivial and I have been doing it for 10 years without problems.
Today for the first time a colleague executing this piece of code calls me
and shows me that an error is raised with the .Additem method (Type
mismatch). The debugger says rngCell is definitely a string (like "Joe
Smith"), not a number, nor anything else.

The strange thing is that it works well on my computer.

When I change
lstEmployees.Additem rngCell
into
lstEmployees.Additem rngCell.Value

then it works on both computers.

Can someone explain me this? Isn't it that .value is the default property of
the Range class?

I am really really lost!

Many thanks and have a good day.

Stefano Gatto
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Is really the default property consistently returned/assigned?

I never rely on the default method, partly because I'm anal and partly
because I want to be unambiguous. And partly because it does not always
work as it 'should'. See:

Sub Works()
Sheets("Sheet1").Range("B1:B2").Clear
Sheets("Sheet1").Range("B1:B2").Value = _
Sheets("Sheet2").Range("A1:A2").Value
End Sub

Sub NoWork()
Sheets("Sheet1").Range("B1:B2").Clear
Sheets("Sheet1").Range("B1:B2") = _
Sheets("Sheet2").Range("A1:A2")
End Sub


--
Jim
"Stefano Gatto" wrote in message
...
|I wrote a procedure a bit like this:
|
| For Each rngCell in rngEmployees
| lstEmployees.Additem rngCell
| Next rngCell
|
| rngEmployees is a one-column range filled with employee's names.
|
| This code is trivial and I have been doing it for 10 years without
problems.
| Today for the first time a colleague executing this piece of code calls me
| and shows me that an error is raised with the .Additem method (Type
| mismatch). The debugger says rngCell is definitely a string (like "Joe
| Smith"), not a number, nor anything else.
|
| The strange thing is that it works well on my computer.
|
| When I change
| lstEmployees.Additem rngCell
| into
| lstEmployees.Additem rngCell.Value
|
| then it works on both computers.
|
| Can someone explain me this? Isn't it that .value is the default property
of
| the Range class?
|
| I am really really lost!
|
| Many thanks and have a good day.
|
| Stefano Gatto


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Is really the default property consistently returned/assigned?

Ok, that's good to hear. To tell you the truth, I also never trusted the
default method, but I wanted to give it a chance this time after all those
years of distrust from my side... Well, I see I made a mistake this time!
Thanks for your answer.
Stefano Gatto


"Jim Rech" wrote:

I never rely on the default method, partly because I'm anal and partly
because I want to be unambiguous. And partly because it does not always
work as it 'should'. See:

Sub Works()
Sheets("Sheet1").Range("B1:B2").Clear
Sheets("Sheet1").Range("B1:B2").Value = _
Sheets("Sheet2").Range("A1:A2").Value
End Sub

Sub NoWork()
Sheets("Sheet1").Range("B1:B2").Clear
Sheets("Sheet1").Range("B1:B2") = _
Sheets("Sheet2").Range("A1:A2")
End Sub


--
Jim
"Stefano Gatto" wrote in message
...
|I wrote a procedure a bit like this:
|
| For Each rngCell in rngEmployees
| lstEmployees.Additem rngCell
| Next rngCell
|
| rngEmployees is a one-column range filled with employee's names.
|
| This code is trivial and I have been doing it for 10 years without
problems.
| Today for the first time a colleague executing this piece of code calls me
| and shows me that an error is raised with the .Additem method (Type
| mismatch). The debugger says rngCell is definitely a string (like "Joe
| Smith"), not a number, nor anything else.
|
| The strange thing is that it works well on my computer.
|
| When I change
| lstEmployees.Additem rngCell
| into
| lstEmployees.Additem rngCell.Value
|
| then it works on both computers.
|
| Can someone explain me this? Isn't it that .value is the default property
of
| the Range class?
|
| I am really really lost!
|
| Many thanks and have a good day.
|
| Stefano Gatto



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Is really the default property consistently returned/assigned?

Hi Stefano,

To continue what Jim Rech wrote,
You assume that XL assumes that lstEmployees.Additem rngCell
will add to you list box what : the range rngCell - value/address - object
itself

To be sure that it works use : lstEmployees.Additem rngCell.value

Regards,
Jean-Yves


"Stefano Gatto" wrote in message
...
I wrote a procedure a bit like this:

For Each rngCell in rngEmployees
lstEmployees.Additem rngCell
Next rngCell

rngEmployees is a one-column range filled with employee's names.

This code is trivial and I have been doing it for 10 years without
problems.
Today for the first time a colleague executing this piece of code calls me
and shows me that an error is raised with the .Additem method (Type
mismatch). The debugger says rngCell is definitely a string (like "Joe
Smith"), not a number, nor anything else.

The strange thing is that it works well on my computer.

When I change
lstEmployees.Additem rngCell
into
lstEmployees.Additem rngCell.Value

then it works on both computers.

Can someone explain me this? Isn't it that .value is the default property
of
the Range class?

I am really really lost!

Many thanks and have a good day.

Stefano Gatto



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Is really the default property consistently returned/assigned?

Salut Jean-Yves,

I read many times that the default property of the range class (or object)
is the value contained in the upper left cell of that same range. Therefore I
am not assuming it, I read it.

But, I must admit this is some years ago and I did not read this again since
a while. So perhaps this functionality was dropped by Microsoft meanwhile.

Anyway I understood the lesson and will never try it again anymore.
Especially that in this case the awful thing is that it works on some PCs and
not on others, which is worse than not working at all.

Merci pour ton aide et bonne journée.

Stefano Gatto


"Jean-Yves" wrote:

Hi Stefano,

To continue what Jim Rech wrote,
You assume that XL assumes that lstEmployees.Additem rngCell
will add to you list box what : the range rngCell - value/address - object
itself

To be sure that it works use : lstEmployees.Additem rngCell.value

Regards,
Jean-Yves


"Stefano Gatto" wrote in message
...
I wrote a procedure a bit like this:

For Each rngCell in rngEmployees
lstEmployees.Additem rngCell
Next rngCell

rngEmployees is a one-column range filled with employee's names.

This code is trivial and I have been doing it for 10 years without
problems.
Today for the first time a colleague executing this piece of code calls me
and shows me that an error is raised with the .Additem method (Type
mismatch). The debugger says rngCell is definitely a string (like "Joe
Smith"), not a number, nor anything else.

The strange thing is that it works well on my computer.

When I change
lstEmployees.Additem rngCell
into
lstEmployees.Additem rngCell.Value

then it works on both computers.

Can someone explain me this? Isn't it that .value is the default property
of
the Range class?

I am really really lost!

Many thanks and have a good day.

Stefano Gatto






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
Why doesn't status bar update consistently? [email protected][_2_] Excel Programming 16 February 1st 06 07:53 AM
CPU Usage consistently above 75% hparteep Excel Discussion (Misc queries) 1 October 27th 05 02:56 PM
Runtime error 380: Could not set the List property. invalid property value of listbox jasgrand Excel Programming 0 October 6th 04 09:28 PM
Strange behaviour of default property Vasant Nanavati Excel Programming 0 October 13th 03 03:07 PM
How to find what object type is returned from Selection property ? Krzysztof Klimczak[_3_] Excel Programming 1 October 2nd 03 11:33 PM


All times are GMT +1. The time now is 10:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"