MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

textbox on a form

  Asked By: Lucas    Date: Oct 03    Category: MS Office    Views: 581

I have a multi-select textbox on a form. The RowSource is a defined
range and works fine. The user wants to select various lines. This
works too.

I need to retrieve which lines he has selected so I can ran a macro
based on the text within the lines. ie first line run the macro, next
selected line run the macro,,,,,, last line run the macro, clear

I will also have to clear all the selected lines after the macro is

The client doesn't like the look of the multi-select list box due to
the squares it loads on the left side.



3 Answers Found

Answer #1    Answered By: Sherrie Thomas     Answered On: Oct 03

You haven't actually indicated that you have a problem or what it is. Are
you looking for an approach your client  will like the look of, or are you
having trouble with some part of your code?

If it's your code that isn't working, you'll need to post what you've done.

Answer #2    Answered By: Anselma Schmidt     Answered On: Oct 03

The problem is:
when a user  selects more than one line  in a textbox, how do I have the macro
run code on each line.

tb_Data is the textbox  with the data.

I've look at:
sub GetSelection
'Need to loop thur only selected  rows
'Only gives the last row selected
'(however, if nothing is selected the
'value is 0 which is the first line
'which isn't good)
SelectionRow = UserForm2.tb_Data.ListIndex

While SelectionRow > -1
'Get data from the 1st column
Column1 = UserForm2.tb_Data.List(SelectionRow)
'Get data from the 2nd column
Column2 = UserForm2.tb_Data.List(SelectionRow, 1)

' Call MyMacro(Column1, Column2)

SelectionRow = SelectionRow - 1

'If I could deselect the current last row I could
'loop backwards and run  MyMacro only on all
'selected lines

end sub

Answer #3    Answered By: Dang Tran     Answered On: Oct 03

I assume you mean that tb_Data is a listbox or a combobox, rather than a
textbox? I don't think you can do what you want to do with a textbox.

For a listbox, you need to scan through and find the selected  lines.
Google will find you information on doing it. The following link
http://www.ozgrid.com/forum/showthread.php?t=37103 is a good example. Just
call your macro, instead of putting the indexes into an array.

Didn't find what you were looking for? Find more on textbox on a form Or get search suggestion and latest updates.