PC Review


Reply
Thread Tools Rate Thread

Copy from one box to another on a user form

 
 
=?Utf-8?B?SkxSLU1hcnQ=?=
Guest
Posts: n/a
 
      13th Nov 2007
Please can someone help. I have a user form with two list boxes on it. One on
the left and one on the right. The LH box has a list of choices and the RH
box is empty. I want a user to highlight a choice or choices in the left box
and by clicking a button with an arrow on it pointing to the RH box it will
populate the RH box with this choice. Having created a list of choices in the
RH box I then want to create a space seperated string of these choices.

Anyone done something similar before?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      13th Nov 2007
Make sure you set your multiselect option to select multiple or extended,
then put this in the buttons click event.

For i = 0 To ListBox1.ListCount - 1
On Error Resume Next
If ListBox1.Selected(i) = True Then
ListBox2.AddItem ListBox1.List(i)
End If
Next i

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"JLR-Mart" wrote:

> Please can someone help. I have a user form with two list boxes on it. One on
> the left and one on the right. The LH box has a list of choices and the RH
> box is empty. I want a user to highlight a choice or choices in the left box
> and by clicking a button with an arrow on it pointing to the RH box it will
> populate the RH box with this choice. Having created a list of choices in the
> RH box I then want to create a space seperated string of these choices.
>
> Anyone done something similar before?

 
Reply With Quote
 
=?Utf-8?B?SkxSLU1hcnQ=?=
Guest
Posts: n/a
 
      13th Nov 2007
Thanks John, nearly there. If I wanted the selection to 'move' from one box
to the other rather than 'copy' how would that work? So if I've selected it
and put it in the box on the RH side it's no longer an option in the LH side?

"John Bundy" wrote:

> Make sure you set your multiselect option to select multiple or extended,
> then put this in the buttons click event.
>
> For i = 0 To ListBox1.ListCount - 1
> On Error Resume Next
> If ListBox1.Selected(i) = True Then
> ListBox2.AddItem ListBox1.List(i)
> End If
> Next i
>
> --
> -John
> Please rate when your question is answered to help us and others know what
> is helpful.
>
>
> "JLR-Mart" wrote:
>
> > Please can someone help. I have a user form with two list boxes on it. One on
> > the left and one on the right. The LH box has a list of choices and the RH
> > box is empty. I want a user to highlight a choice or choices in the left box
> > and by clicking a button with an arrow on it pointing to the RH box it will
> > populate the RH box with this choice. Having created a list of choices in the
> > RH box I then want to create a space seperated string of these choices.
> >
> > Anyone done something similar before?

 
Reply With Quote
 
Keith74
Guest
Posts: n/a
 
      13th Nov 2007

>
> > For i = 0 To ListBox1.ListCount - 1
> > On Error Resume Next
> > If ListBox1.Selected(i) = True Then
> > ListBox2.AddItem ListBox1.List(i)

ListBox1.RemoveItem i
> > End If
> > Next i

>


hth

Keith

 
Reply With Quote
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      13th Nov 2007
just add the line i have commented
Private Sub CommandButton1_Click()

For i = 0 To ListBox1.ListCount - 1
On Error Resume Next
If ListBox1.Selected(i) = True Then
ListBox2.AddItem ListBox1.List(i)
ListBox1.RemoveItem (i) 'add this
End If
Next i

End Sub

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"JLR-Mart" wrote:

> Thanks John, nearly there. If I wanted the selection to 'move' from one box
> to the other rather than 'copy' how would that work? So if I've selected it
> and put it in the box on the RH side it's no longer an option in the LH side?
>
> "John Bundy" wrote:
>
> > Make sure you set your multiselect option to select multiple or extended,
> > then put this in the buttons click event.
> >
> > For i = 0 To ListBox1.ListCount - 1
> > On Error Resume Next
> > If ListBox1.Selected(i) = True Then
> > ListBox2.AddItem ListBox1.List(i)
> > End If
> > Next i
> >
> > --
> > -John
> > Please rate when your question is answered to help us and others know what
> > is helpful.
> >
> >
> > "JLR-Mart" wrote:
> >
> > > Please can someone help. I have a user form with two list boxes on it. One on
> > > the left and one on the right. The LH box has a list of choices and the RH
> > > box is empty. I want a user to highlight a choice or choices in the left box
> > > and by clicking a button with an arrow on it pointing to the RH box it will
> > > populate the RH box with this choice. Having created a list of choices in the
> > > RH box I then want to create a space seperated string of these choices.
> > >
> > > Anyone done something similar before?

 
Reply With Quote
 
=?Utf-8?B?SkxSLU1hcnQ=?=
Guest
Posts: n/a
 
      14th Nov 2007
Thanks for the responses...much appreciated

"John Bundy" wrote:

> just add the line i have commented
> Private Sub CommandButton1_Click()
>
> For i = 0 To ListBox1.ListCount - 1
> On Error Resume Next
> If ListBox1.Selected(i) = True Then
> ListBox2.AddItem ListBox1.List(i)
> ListBox1.RemoveItem (i) 'add this
> End If
> Next i
>
> End Sub
>
> --
> -John
> Please rate when your question is answered to help us and others know what
> is helpful.
>
>
> "JLR-Mart" wrote:
>
> > Thanks John, nearly there. If I wanted the selection to 'move' from one box
> > to the other rather than 'copy' how would that work? So if I've selected it
> > and put it in the box on the RH side it's no longer an option in the LH side?
> >
> > "John Bundy" wrote:
> >
> > > Make sure you set your multiselect option to select multiple or extended,
> > > then put this in the buttons click event.
> > >
> > > For i = 0 To ListBox1.ListCount - 1
> > > On Error Resume Next
> > > If ListBox1.Selected(i) = True Then
> > > ListBox2.AddItem ListBox1.List(i)
> > > End If
> > > Next i
> > >
> > > --
> > > -John
> > > Please rate when your question is answered to help us and others know what
> > > is helpful.
> > >
> > >
> > > "JLR-Mart" wrote:
> > >
> > > > Please can someone help. I have a user form with two list boxes on it. One on
> > > > the left and one on the right. The LH box has a list of choices and the RH
> > > > box is empty. I want a user to highlight a choice or choices in the left box
> > > > and by clicking a button with an arrow on it pointing to the RH box it will
> > > > populate the RH box with this choice. Having created a list of choices in the
> > > > RH box I then want to create a space seperated string of these choices.
> > > >
> > > > Anyone done something similar before?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use VBA to copy User Form from 1 workbook to another? =?Utf-8?B?TWlrZVp6?= Microsoft Excel Programming 29 24th Sep 2009 11:36 PM
Copy from one user form to another Stockwell43 Microsoft Access 4 30th Dec 2008 09:19 PM
Copy or Print from User Form? =?Utf-8?B?U2hlbGx5?= Microsoft Excel Programming 2 28th Mar 2007 11:54 AM
USER FORM COPY tkraju via OfficeKB.com Microsoft Excel Programming 2 9th Aug 2006 05:32 AM
Form to email me and copy the user Jason Swain Microsoft Frontpage 1 25th Nov 2003 10:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:29 AM.