Rabu, 18 Februari 2015

Re: [ExcelVBA] How do you get code assigned to a ListBox to run even when the same item is selected?

 



Putting controls directly onto Worksheets cuts down on the events that they will generate,  They generate more events when on a form.  Looks as though listboxes are limited to only trigger on changes and not clicks (which is consistent with "change" events for cells, which also don't fire if you don't change the contents).
 
That said, I don't see from your code what your purpose is in using a listbox, rather than a button.  Could you give us a short description of what you're actually doing with these controls, and we'll think about other ways of achieving the result.

Regards, Dave S
 
----- Original Message -----
Sent: Thursday, February 19, 2015 2:39 PM
Subject: Re: [ExcelVBA] How do you get code assigned to a ListBox to run even when the same item is selected?

Thanks for the suggestion, David.

However, when I replace

Sub Game2_Click()

with

Sub Game2_MouseUp()

it acts the same as with Click.  That is, it only executes the statements in the Sub if I click on a different item from the drop down list.   If I click on the same item, it doesn't execute the statements in the Sub.

For good measure, I tried MouseDown(), too.   Still the same behavior.

Best,
Dunbar




---In ExcelVBA@yahoogroups.com, <yahoo@...> wrote :

Hi H Dunbar

That's the way it is.  However if you use MouseUp rather than click it will fire anywhere.

Regards
David Grugeon


On 15 February 2015 at 03:04, h_dunbar@... [ExcelVBA] <ExcelVBA@yahoogroups.com> wrote:


Greetings!


I have a ListBox on Worksheet "PlayList".   When the macro below is assigned to the ListBox, it does what I want, as long as I choose an item on the list different from the previous selection:


<code> 

Sub Game2_Click()

  

      Range("ChangedGame2").Value = "Yes"

      UnProtectSheet ("PlayList")

        Range("CustomName1").Offset(0, 1).Value = ""

      ProtectSheet ("PlayList")


End Sub

</code>


But when I select the same (as previous) item from the drop-down list, nothing happens.  I have tried replacing "Click" with "AfterUpdate", "KeyPress", "BeforeUpdate", "Selection", and "Select"  (basically, everything I could find on Google, with the exception of "Kardashian").    With each of those events, the code runs only if I've picked a new item from the List.


How can I get that code to run every time I click on the ListBox? 

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5645 / Virus Database: 4284/9141 - Release Date: 02/18/15

__._,_.___

Posted by: "David Smart" <smartware.consulting@gmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------

.

__,_._,___

Tidak ada komentar:

Posting Komentar