trouble with a listindex value...
Help!
Using XL 2000, I'm trying to assign and show a listindex value to an item selected in the list. Although the procedure is relatively simple, I have added the code i'm currently using to help explain what is going on. I have a listbox on userform1 which is populated thus: ListBox1.Clear With ListBox1 .RowSource = "Info!A1:A12" .MultiSelect = fmMultiSelectMulti .ListStyle = fmListStyleOption End With I can then scroll through the listbox which contains 16 items to select one or many. When selected, I need the listindex value to be appended to a list (assuming more than one item is selected) which is then displayed in the worksheets activecell. The following does not quite fulfil this requirement as the active cell only appends the previous listindex value. if items 1,3,5,9 were selected (or at least their equivelant listbox text, activell shows 9,9,9,9 - the previous 3 were overwritten. Private Sub ListBox1_Change() SelectedQA = "" With ListBox1 For iCt = 0 To .ListCount - 1 If .Selected(iCt) = True Then _ SelectedQA = SelectedQA & .ListIndex + 1 _& ", " Next iCt End With If Len(SelectedQA) 0 Then _ SelectedQA = Left(SelectedQA, Len(SelectedQA)) ActiveCell = SelectedQA ' End Sub I hope this explains my problem. Any solutions/guidance appreciated. Thanks, Paul |
trouble with a listindex value...
Change
SelectedQA = SelectedQA & .ListIndex + 1 to SelectedQA = SelectedQA & iCt + 1 Robert Flanagan Macro Systems Delaware, U.S. 302-234-9857 http://www.add-ins.com Productivity add-ins and downloadable books on VB macros for Excel "Paul" wrote in message ... Help! Using XL 2000, I'm trying to assign and show a listindex value to an item selected in the list. Although the procedure is relatively simple, I have added the code i'm currently using to help explain what is going on. I have a listbox on userform1 which is populated thus: ListBox1.Clear With ListBox1 .RowSource = "Info!A1:A12" .MultiSelect = fmMultiSelectMulti .ListStyle = fmListStyleOption End With I can then scroll through the listbox which contains 16 items to select one or many. When selected, I need the listindex value to be appended to a list (assuming more than one item is selected) which is then displayed in the worksheets activecell. The following does not quite fulfil this requirement as the active cell only appends the previous listindex value. if items 1,3,5,9 were selected (or at least their equivelant listbox text, activell shows 9,9,9,9 - the previous 3 were overwritten. Private Sub ListBox1_Change() SelectedQA = "" With ListBox1 For iCt = 0 To .ListCount - 1 If .Selected(iCt) = True Then _ SelectedQA = SelectedQA & .ListIndex + 1 _& ", " Next iCt End With If Len(SelectedQA) 0 Then _ SelectedQA = Left(SelectedQA, Len(SelectedQA)) ActiveCell = SelectedQA ' End Sub I hope this explains my problem. Any solutions/guidance appreciated. Thanks, Paul |
trouble with a listindex value...
Thank you.could not see the wood for the trees!
Paul -----Original Message----- Change SelectedQA = SelectedQA & .ListIndex + 1 to SelectedQA = SelectedQA & iCt + 1 Robert Flanagan Macro Systems Delaware, U.S. 302-234-9857 http://www.add-ins.com Productivity add-ins and downloadable books on VB macros for Excel "Paul" wrote in message ... Help! Using XL 2000, I'm trying to assign and show a listindex value to an item selected in the list. Although the procedure is relatively simple, I have added the code i'm currently using to help explain what is going on. I have a listbox on userform1 which is populated thus: ListBox1.Clear With ListBox1 .RowSource = "Info!A1:A12" .MultiSelect = fmMultiSelectMulti .ListStyle = fmListStyleOption End With I can then scroll through the listbox which contains 16 items to select one or many. When selected, I need the listindex value to be appended to a list (assuming more than one item is selected) which is then displayed in the worksheets activecell. The following does not quite fulfil this requirement as the active cell only appends the previous listindex value. if items 1,3,5,9 were selected (or at least their equivelant listbox text, activell shows 9,9,9,9 - the previous 3 were overwritten. Private Sub ListBox1_Change() SelectedQA = "" With ListBox1 For iCt = 0 To .ListCount - 1 If .Selected(iCt) = True Then _ SelectedQA = SelectedQA & .ListIndex + 1 _& ", " Next iCt End With If Len(SelectedQA) 0 Then _ SelectedQA = Left(SelectedQA, Len (SelectedQA)) ActiveCell = SelectedQA ' End Sub I hope this explains my problem. Any solutions/guidance appreciated. Thanks, Paul . |
All times are GMT +1. The time now is 11:08 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com