Got any Excel/VBA Questions? Free Excel Help
Add 2 CommandButtons to your UserForm and Name them MoveUp and MoveDown. Then, use the RowSource Property of the Multi Column ListBox to fill the ListBox with a Named Range. Ensure this named range has headings BUT are no included in the range name definition. Set the ColumnHeads Property of the ListBox to True and the ColumnCount to as many columns as the named range has Columns. Set the ColumnWidths as needed.
Private Sub MoveDown_Click() Dim lCurrentListIndex As Long Dim strRowSource As String Dim strAddress As String Dim strSheetName As String With ListBox1 If .ListIndex < 0 Or .ListIndex = .ListCount - 1 Then Exit Sub lCurrentListIndex = .ListIndex + 1 strRowSource = .RowSource strAddress = Range(strRowSource).Address strSheetName = Range(strRowSource).Parent.Name .RowSource = vbNullString With Range(strRowSource) .Rows(lCurrentListIndex).Cut .Rows(lCurrentListIndex + 2).Insert Shift:=xlDown End With Sheets(strSheetName).Range(strAddress).Name = strRowSource .RowSource = strRowSource .Selected(lCurrentListIndex) = True End With End Sub Private Sub MoveUp_Click() Dim lCurrentListIndex As Long Dim strRowSource As String Dim strAddress As String Dim strSheetName As String With ListBox1 If .ListIndex < 1 Then Exit Sub lCurrentListIndex = .ListIndex + 1 strRowSource = .RowSource strAddress = Range(strRowSource).Address strSheetName = Range(strRowSource).Parent.Name .RowSource = vbNullString With Range(strRowSource) .Rows(lCurrentListIndex).Cut .Rows(lCurrentListIndex - 1).Insert Shift:=xlDown End With Sheets(strSheetName).Range(strAddress).Name = strRowSource .RowSource = strRowSource .Selected(lCurrentListIndex - 2) = True End With End Sub
See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.