View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Still can't get it right

Bit of a shame, I liked the first code more <vbg

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"asmenut" wrote in message
...
That's the ticket Bob. Many thanks. Now I can finish the automation

coding
properly. You Da Man.

"Bob Phillips" wrote:

You didn't mention that you wanted to move the source as well.

Here is another cut

Private Sub CommandDown_Click()
Dim vTemp, vtemp1

With ListBox1
If .ListIndex < .ListCount - 1 Then
Rows(.ListIndex + 1).Cut
Range("A" & .ListIndex + 3).Insert Shift:=xlDown
vTemp = .ListIndex
LoadListbox
.ListIndex = vTemp + 1
End If
End With

End Sub

Private Sub CommandOK_Click()
Unload Me
End Sub

Private Sub CommandUp_Click()
Dim vTemp

With ListBox1
If .ListIndex 0 Then
Rows(.ListIndex + 1).Cut
Range("A" & .ListIndex).Insert Shift:=xlDown
vTemp = .ListIndex
LoadListbox
.ListIndex = vTemp - 1
End If
End With

End Sub

Private Sub UserForm_Initialize()

LoadListbox
ListBox1.ListIndex = 0

End Sub

Sub LoadListbox()
Dim ColCnt As Integer
Dim Rng As Range
Dim cw, c, i

' Fill the List Box
ColCnt = ActiveSheet.Columns.Count
Set Rng = ActiveSheet.Range("A1:P34")
With ListBox1
.ColumnCount = ColCnt
.List = Rng.Value
cw = ""

For c = 1 To .ColumnCount
cw = cw & Rng.Columns(c).Width & ";"
Next c
.ColumnWidths = cw
End With
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"asmenut" wrote in message
...
I am still having trouble getting the re-order to work on the

multicolumn
listbox.

I took the advice of Dick, Tom and Bob; Rewrote the code to

incorporate
the
advice for getting the listbox to show without errors, but I can't

seem to
get it to write the new order into the spredsheet? Any ideas.

Code Below

Private Sub CommandDown_Click()
Dim vTemp, vtemp1

With ListBox1
If .ListIndex < .ListCount - 1 Then
vTemp = .Value
vtemp1 = .List(.ListIndex, 2)
.List(.ListIndex) = .List(.ListIndex + 1)
.List(.ListIndex + 1) = vTemp
.List(.ListIndex + 1, 2) = vtemp1
.ListIndex = .ListIndex + 1
End If
End With

End Sub

Private Sub CommandOK_Click()
Unload Me
End Sub

Private Sub CommandUp_Click()
Dim vTemp, vtemp1

With ListBox1
If .ListIndex 0 Then
vTemp = .Value
vtemp1 = .List(.ListIndex, 2)
.List(.ListIndex) = .List(.ListIndex - 1)
.List(.ListIndex, 2) = .List(.ListIndex - 1, 2)
.List(.ListIndex - 1) = vTemp
.List(.ListIndex - 1, 2) = vtemp1
.ListIndex = .ListIndex - 1
End If
End With

End Sub

Private Sub UserForm_Initialize()
Dim ColCnt As Integer
Dim Rng As Range

' Fill the List Box
ColCnt = ActiveSheet.Columns.Count
Set Rng = ActiveSheet.Range("A1:P34")
With ListBox1
.ColumnCount = ColCnt
.List = Rng.Value
cw = ""

For c = 1 To .ColumnCount
cw = cw & Rng.Columns(c).Width & ";"
Next c
.ColumnWidths = cw
.ListIndex = 0
End With


End Sub