AllExperts > Experts 
Search      

Visual Basic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ravindra
Expertise
visual basic application programming from design to access information, sql, engineering and commercial applications. access databases, excel. Optional: 1)a large number of people want me to do work which takes some time and effort. Pl.note that i would like to be paid for such work. 2) if you want me to spend quality time and do special work, i expect to be paid a reasonable price for my time. 3) if you are pleased with my reply you could consider a donation of 1$. 4) you can visit my website http://ravindra.coolpage.biz (under constrn)

Experience

Past/Present clients
project work for a Norway company, and a Canadian company completed. Freelance Project work and Teaching
teaching vb

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Excel listbox

Topic: Visual Basic



Expert: Ravindra
Date: 9/3/2008
Subject: Excel listbox

Question
QUESTION: Hi,
Can you please help me with my problem regarding listbox indexing. I am trying to assign a specific value for every item in my listbox but my Excel version have no  "Itemdata" options. tnx

ANSWER: there is no "your version" " "my version" here.

there is no itemdata proeprty for the listbox

i do not follow your logic. the listbox in excel links to series of cells in excel sheet.
what is this indexing etc, i cannot comprehend.

---------- FOLLOW-UP ----------

QUESTION: Hi,

I am using Excel 2007.I have a command button that when clicked will produce list of items in the list box. example

"My Process1"
"My Process2"
"My Process3"
"My Process4"
"My Process5"

So there are 5 items in my listbox. What I want to do is that if I select 1 or a couple of items in the listbox and push a command button it will perform a specific task depending on the items selected. The problem is I do not know how to determine which items on the lists are selected. Is there a way to do that.
In Excel 2000 when you add an item the syntax is
   List1.AddItem (ItemName,ItemIndex) so there is no problem in verifying if the specified item is selected or not.
I hope you can help me with this one.
Thaks in advance.

ANSWER: now your question is  clear

use this code

Private Sub CommandButton1_Click()
Dim x As Integer, y As Integer
y = 2
x = ListBox1.ListCount
For x = 0 To x - 1

Cells(y, 2) = ListBox1.List(x)
Cells(y, 3) = x
y = y + 1
Next
End Sub

---------- FOLLOW-UP ----------

QUESTION: Hi,
Thanks for the info. Please see my sample below

Private Sub List1_Change()
Dim Mysel
Dim id As Integer
Dim x As Integer
MYsel = MYsel & " " & List1.ListIndex
End Sub

In the procedure above whenever there occurs a change in the list(if I select or deselect a specified item), I get the listindex number and concatenate it in Mysel variable. example is "0 0 2 2 2 5 8 10 15". the problem is when you "select" or "deselect" a specific item , the same index will repeat itself. I only need the listindex of the highlighted items.  so in the example i should only get "2 5 8 10 15". In the case of zero, it is selected and deselected so it is no longer in the highlighted state.Is there another way beside Private Sub List1_Change() procedure? or a better way?


Answer
try this:

Private Sub ListBox1_Click()
Static Myse As String
Dim id As Integer
Dim x As Integer
Myse = Myse & Space(1) & ListBox1.ListIndex
Cells(3, 1) = Myse
End Sub

you need to make changes that get the desired result. you need to try out yourself

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.