coliervile
02-25-2008, 08:51 AM
I'm having problem figuring how to sort (code) the worksheet "Leave Request" and update the listbox1 in the userform "frmRequest" when changes have been made using the "Make Changes" command button on the userform "frmRequest". The data in both the worksheet "Leave Request" and listbox1 on "frmRequest" does update, but I cant get the sort part figured out. I want the sort on the worksheet "Leave Request" as follows:
(this is an example not the actual coding, but I did try it)http://vbaexpress.com/forum/images/smilies/102.gif
Worksheets("Leave Request")
.Range("A:E").Sort Key1:=.Range("D2"), Order1:=xlAscending, _
Key2:=.Range("B2"), Order2:=xlAscending, _
Header:=xlYes
then after the sort is done update the "frmRequest"- listbox1.
Best regards,
Charlie
Private Sub CommandButton6_Click()
With frmRequest.ListBox1
'Check for selected item
If (.Value <> vbNullString) Then
Range(.RowSource)(.ListIndex + 1, 1).Value = frmRequest.TextBox1.Value
Range(.RowSource)(.ListIndex + 1, 2).Value = frmRequest.TextBox2.Value
Range(.RowSource)(.ListIndex + 1, 3).Value = frmRequest.TextBox3.Value
Range(.RowSource)(.ListIndex + 1, 4).Value = frmRequest.TextBox4.Value
Range(.RowSource)(.ListIndex + 1, 5).Value = frmRequest.TextBox5.Value
Else
MsgBox "Please Enter Data"
End If
End With
End Sub
(this is an example not the actual coding, but I did try it)http://vbaexpress.com/forum/images/smilies/102.gif
Worksheets("Leave Request")
.Range("A:E").Sort Key1:=.Range("D2"), Order1:=xlAscending, _
Key2:=.Range("B2"), Order2:=xlAscending, _
Header:=xlYes
then after the sort is done update the "frmRequest"- listbox1.
Best regards,
Charlie
Private Sub CommandButton6_Click()
With frmRequest.ListBox1
'Check for selected item
If (.Value <> vbNullString) Then
Range(.RowSource)(.ListIndex + 1, 1).Value = frmRequest.TextBox1.Value
Range(.RowSource)(.ListIndex + 1, 2).Value = frmRequest.TextBox2.Value
Range(.RowSource)(.ListIndex + 1, 3).Value = frmRequest.TextBox3.Value
Range(.RowSource)(.ListIndex + 1, 4).Value = frmRequest.TextBox4.Value
Range(.RowSource)(.ListIndex + 1, 5).Value = frmRequest.TextBox5.Value
Else
MsgBox "Please Enter Data"
End If
End With
End Sub