Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
hello.
The userform have two buttons and one listbox. i want to move up or down a item of listbox. first, select the item of listbox and if press a button(up) of two button, the item move up one step.... but vba code, i don't know that. *** Sent via Developersdex http://www.developersdex.com *** |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
Hi,
Try this. '----------------------------- Private Sub CommandButton1_Click() If ListBox1.ListIndex 0 Then ListBox1.ListIndex = ListBox1.ListIndex - 1 End If End Sub Private Sub CommandButton2_Click() If ListBox1.ListIndex < ListBox1.ListCount - 1 Then ListBox1.ListIndex = ListBox1.ListIndex + 1 End If End Sub Private Sub UserForm_Initialize() ListBox1.List = Array(1, 2, 3, 4, 5, 6) CommandButton1.Caption = "Up" CommandButton2.Caption = "Down" End Sub '----------------------------- Cheers Andy x taol wrote: hello. The userform have two buttons and one listbox. i want to move up or down a item of listbox. first, select the item of listbox and if press a button(up) of two button, the item move up one step.... but vba code, i don't know that. *** Sent via Developersdex http://www.developersdex.com *** -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
Private Sub CommandButton2_Click()
With Me.ListBox1 If .ListIndex 0 Then .ListIndex = .ListIndex - 1 End With End Sub Private Sub CommandButton3_Click() With Me.ListBox1 If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1 End With End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "x taol" wrote in message ... hello. The userform have two buttons and one listbox. i want to move up or down a item of listbox. first, select the item of listbox and if press a button(up) of two button, the item move up one step.... but vba code, i don't know that. *** Sent via Developersdex http://www.developersdex.com *** |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
oh, no... i don't want to move just. i want to move of the item. for example, item aaa bbb ccc ddd in that case, if "ccc" is selected, press the Up button, the sequency is that. aaa ccc bbb ddd *** Sent via Developersdex http://www.developersdex.com *** |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
To move list items up and down try
Private Sub CommandButton1_Click() Dim strTemp As String Dim lngIndex As Long If ListBox1.ListIndex 0 Then lngIndex = ListBox1.ListIndex strTemp = ListBox1.List(lngIndex - 1) ListBox1.List(lngIndex - 1) = ListBox1.List(lngIndex) ListBox1.List(lngIndex) = strTemp ListBox1.ListIndex = lngIndex - 1 End If End Sub Private Sub CommandButton2_Click() Dim strTemp As String Dim lngIndex As Long If ListBox1.ListIndex = 0 And _ ListBox1.ListIndex < (ListBox1.ListCount - 1) Then lngIndex = ListBox1.ListIndex strTemp = ListBox1.List(lngIndex + 1) ListBox1.List(lngIndex + 1) = ListBox1.List(lngIndex) ListBox1.List(lngIndex) = strTemp ListBox1.ListIndex = lngIndex + 1 End If End Sub Cheers Andy x taol wrote: oh, no... i don't want to move just. i want to move of the item. for example, item aaa bbb ccc ddd in that case, if "ccc" is selected, press the Up button, the sequency is that. aaa ccc bbb ddd *** Sent via Developersdex http://www.developersdex.com *** -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
Here is one way.
What I am doing is capturing the listbox elements in an array and changing the array, then reloadingf the listbox. I have included a dummy routine to show how I load to start etc. Option Explicit Dim aryList Private Sub CommandButton1_Click() Dim i As Long, j As Long Dim iStart As Long Dim iEnd As Long iStart = Evaluate("MIN(IF(A1:A1000<"""",MONTH(A1:A1000)))" ) iEnd = Evaluate("MAX(IF(A1:A1000<"""",MONTH(A1:A1000)))" ) ReDim aryList(1 To iEnd - iStart + 1) For i = iStart To iEnd j = j + 1 aryList(j) = Format(DateSerial(Year(Date), i, 1), "mmmm") Next i ListBox1.List = aryList End Sub Private Sub cmdUp_Click() Dim tmp With Me.ListBox1 If .ListIndex 0 Then tmp = aryList(.ListIndex) aryList(.ListIndex) = aryList(.ListIndex + 1) aryList(.ListIndex + 1) = tmp .List = aryList End If End With End Sub Private Sub cmdDown_Click() Dim tmp With Me.ListBox1 If .ListIndex < .ListCount - 1 Then tmp = aryList(.ListIndex + 1) aryList(.ListIndex + 1) = aryList(.ListIndex + 2) aryList(.ListIndex + 2) = tmp .List = aryList End If End With End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "x taol" wrote in message ... oh, no... i don't want to move just. i want to move of the item. for example, item aaa bbb ccc ddd in that case, if "ccc" is selected, press the Up button, the sequency is that. aaa ccc bbb ddd *** Sent via Developersdex http://www.developersdex.com *** |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
thank you Andy Pope if top button press, the select item move top. how code? *** Sent via Developersdex http://www.developersdex.com *** |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
on Listbox in Userform....
Private Sub cmdBottom_Click()
ListBox1.ListIndex = ListBox1.ListCount - 1 End Sub Private Sub cmdTop_Click() ListBox1.ListIndex = 0 End Sub -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "x taol" wrote in message ... thank you Andy Pope if top button press, the select item move top. how code? *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Listbox in UserForm | Excel Discussion (Misc queries) | |||
userform listbox cannot get listbox.value to transfer back to main sub | Excel Programming | |||
UserForm Listbox in VBC | Excel Discussion (Misc queries) | |||
UserForm with ListBox | Excel Programming | |||
UserForm ListBox | Excel Programming |