Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Link the ListCount to a Label automatically.

Happy New Year to all....

I have a listbox(Listbox1) and a label (Label1).

I want to display the count in the label as in code..
Label1.caption = "List Count : " & Listbox1.ListCount

But I am adding and deleting the contents in different places in the
code.
Can there be way to Link that deynamically so that whenever the
ListCount is changed, the Label1 will get updated.

I even tried to put that code in the Sub Listbox1_Change()
But its not conclusive. Some operations it will be Updated, but
sometimes Not.

I also tried the event - Sub ListBin_AfterUpdate(), but thats the same
situation.

Can anyone help?


Thanks & Regards
Joe

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Link the ListCount to a Label automatically.

I've not used Lists at all, but I suspect you could use a worksheet change
event to do what you want.

Here is some code that might be useful. You need to go to the sheet that
the list is on, click on the worksheet tab and select View Code. Then paste
it in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myListObject As ListObject
Dim myRange As Range

For Each myListObject In Me.ListObjects

If Not Intersect(Target, myListObject.Range) Is Nothing Then
MsgBox ("You have changed a value in the list " & myListObject.Name)
End If

For Each myRange In myListObject.Range
Debug.Print myListObject.Name, myRange.Address
Next myRange
Next myListObject
End Sub


--
HTH,
Barb Reinhardt



"Joe" wrote:

Happy New Year to all....

I have a listbox(Listbox1) and a label (Label1).

I want to display the count in the label as in code..
Label1.caption = "List Count : " & Listbox1.ListCount

But I am adding and deleting the contents in different places in the
code.
Can there be way to Link that deynamically so that whenever the
ListCount is changed, the Label1 will get updated.

I even tried to put that code in the Sub Listbox1_Change()
But its not conclusive. Some operations it will be Updated, but
sometimes Not.

I also tried the event - Sub ListBin_AfterUpdate(), but thats the same
situation.

Can anyone help?


Thanks & Regards
Joe


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Link the ListCount to a Label automatically.

On Jan 1, 2:08*pm, Barb Reinhardt
wrote:
I've not used Lists at all, but I suspect you could use a worksheet change
event to do what you want. *

Here is some code that might be useful. *You need to go to the sheet that
the list is on, click on the worksheet tab and select View Code. *Then paste
it in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myListObject As ListObject
Dim myRange As Range

For Each myListObject In Me.ListObjects

* * If Not Intersect(Target, myListObject.Range) Is Nothing Then
* * * * MsgBox ("You have changed a value in the list " & myListObject.Name)
* * End If

* * For Each myRange In myListObject.Range
* * * * Debug.Print myListObject.Name, myRange.Address
* * Next myRange
Next myListObject
End Sub

--
HTH,
Barb Reinhardt



"Joe" wrote:
Happy New Year to all....


I have a listbox(Listbox1) and a label (Label1).


I want to display the count in the label as in code..
Label1.caption = "List Count : " & Listbox1.ListCount


But I am adding and deleting the contents in different places in the
code.
Can there be way to Link that deynamically so that whenever the
ListCount is changed, the Label1 will get updated.


I even tried to put that code in the Sub Listbox1_Change()
But its not conclusive. *Some operations it will be Updated, but
sometimes Not.


I also tried the event - Sub ListBin_AfterUpdate(), but thats the same
situation.


Can anyone help?


Thanks & Regards
Joe- Hide quoted text -


- Show quoted text -


Thanks Barb ...

I have not understood it fully...
But what I understood is...
The ListBox is somehow linked to a worksheet range.. (i dont know
how)..
and you are checking if there is a change in that Range and thus its
implied that there is a change in the ListBox

It sounds nice but for my application I can not adopt that...

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
Automatically update Value for data label Nav Charts and Charting in Excel 0 June 18th 08 12:37 PM
MyArray (ComboBox.ListCount-1) possible? LuisE Excel Programming 2 November 26th 07 08:28 PM
Is it possible to Link a Label control to a cell ? Ben Excel Worksheet Functions 0 July 9th 07 10:32 PM
Link Cell to Label Caption papaitaliano Excel Discussion (Misc queries) 1 March 21st 06 05:21 PM
Link cell to Label Caption papaitaliano Excel Programming 2 March 21st 06 05:00 PM


All times are GMT +1. The time now is 01:26 AM.

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

About Us

"It's about Microsoft Excel"