Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Must Be Missing Something Obvious About ListBoxes

I have a four-column list box with the following code in the change
event (not all columns are used in this example):
..
..
With lstbox
Range("Name1").Value = .Columns(1)
Range("Name2").Value = .Columns(0)
Range("Name3").Value = .Columns(2)
end with
..
..

If I comment out the last two range lines, it works. If I don't, a
very strange thing happens. If I place a breakpoint on the first line,
the executions breaks here as normal; but when I hit play it breaks on
this line again, and, on the third play, throws exception #381.
Meanwhile, I notice that the lstbox reference has become null.

If I dim a module-level interger as a counter (adding one to it at the
top of the event handler), it appears that the code is being called 3
times.

Am I using the Columns property incorrectly? Why is this code
executing three times?

Thanks,
Johnny

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Must Be Missing Something Obvious About ListBoxes

Your events are recursive. When you assign the value to the cell a change is
initiated and the event fires again. You need to change the application
settings as follows (it is safest to use an error handler here)

on error goto errorhandler
application.enableevents = false
....
With lstbox
Range("Name1").Value = .Columns(1)
Range("Name2").Value = .Columns(0)
Range("Name3").Value = .Columns(2)
end with
....
ErrorHandler:
application.enableevents = true
End sub
--
HTH...

Jim Thomlinson


"Johnny Meredith" wrote:

I have a four-column list box with the following code in the change
event (not all columns are used in this example):
..
..
With lstbox
Range("Name1").Value = .Columns(1)
Range("Name2").Value = .Columns(0)
Range("Name3").Value = .Columns(2)
end with
..
..

If I comment out the last two range lines, it works. If I don't, a
very strange thing happens. If I place a breakpoint on the first line,
the executions breaks here as normal; but when I hit play it breaks on
this line again, and, on the third play, throws exception #381.
Meanwhile, I notice that the lstbox reference has become null.

If I dim a module-level interger as a counter (adding one to it at the
top of the event handler), it appears that the code is being called 3
times.

Am I using the Columns property incorrectly? Why is this code
executing three times?

Thanks,
Johnny


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Must Be Missing Something Obvious About ListBoxes

It seems that you are looking at the properties of the Listbox but trying to
assign values to a range at the same time. I am not sure that flies.


"Johnny Meredith" wrote in message
oups.com...
I have a four-column list box with the following code in the change
event (not all columns are used in this example):
.
.
With lstbox
Range("Name1").Value = .Columns(1)
Range("Name2").Value = .Columns(0)
Range("Name3").Value = .Columns(2)
end with
.
.

If I comment out the last two range lines, it works. If I don't, a
very strange thing happens. If I place a breakpoint on the first line,
the executions breaks here as normal; but when I hit play it breaks on
this line again, and, on the third play, throws exception #381.
Meanwhile, I notice that the lstbox reference has become null.

If I dim a module-level interger as a counter (adding one to it at the
top of the event handler), it appears that the code is being called 3
times.

Am I using the Columns property incorrectly? Why is this code
executing three times?

Thanks,
Johnny



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
I know this is obvious but .. Bony Pony[_3_] Excel Worksheet Functions 3 March 9th 10 01:23 PM
cannot activate smart tags - tried all the obvious sinclaira Excel Discussion (Misc queries) 0 March 12th 07 04:22 PM
A Really Stupid Obvious Question that is Driving Me Nuts Capt. Attitude Excel Discussion (Misc queries) 2 October 18th 06 06:23 PM
Not so obvious Chart? rvExcelNewTip Charts and Charting in Excel 4 June 1st 05 05:14 PM
listboxes [email protected] Excel Programming 2 February 22nd 05 10:31 AM


All times are GMT +1. The time now is 03:03 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"