Dim MyRange As Range, MyMsgbox As Integer, MyControl As Control, i As Long
Private Sub UserForm_Initialize()
ListBox1.List = Range(Sheet1.[A2], Sheet1.[A65536].End(xlUp)).Resize(, 7).Value
End Sub
Private Sub CommandButton1_Click()
MyMsgbox = MsgBox("Ban co chac luu lai chinh sua thong tin cua ID: " & TextBox1, vbYesNo + vbQuestion, "Thông Báo")
If MyMsgbox = vbYes Then
Set MyRange = Range(Sheet1.[A1], Sheet1.[A65536].End(xlUp)).Find(Label6.Caption, LookIn:=xlValues, LookAt:=xlWhole)
For Each MyControl In Controls
If TypeName(MyControl) = "TextBox" Or TypeName(MyControl) = "ComboBox" Then
For i = 0 To 6
If Right(MyControl.Name, 1) = i + 1 Then MyRange.Offset(, i) = MyControl.Text
Next
End If
Next
ListBox1.List = Range(Sheet1.[A2], Sheet1.[A65536].End(xlUp)).Resize(, 7).Value
End If
CommandButton1.Enabled = False
CommandButton2.Enabled = True
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
MyMsgbox = MsgBox("Ban co chac chinh sua thong tin cua ID: " & ListBox1.Value, vbYesNo + vbQuestion, "Thông Báo")
If MyMsgbox = vbYes Then
For Each MyControl In Controls
If TypeName(MyControl) = "TextBox" Or TypeName(MyControl) = "ComboBox" Then
For i = 0 To 6
If Right(MyControl.Name, 1) = i + 1 Then MyControl.Text = ListBox1.Column(i)
Next
End If
Next
Label6.Caption = ListBox1.Value
CommandButton1.Enabled = True
CommandButton2.Enabled = False
ListBox1.List = Range(Sheet1.[A2], Sheet1.[A65536].End(xlUp)).Resize(, 7).Value
End If
End Sub
Private Sub CommandButton2_Click()
Set MyRange = Sheet1.[A65536].End(xlUp).Offset(1)
For Each MyControl In Controls
If TypeName(MyControl) = "TextBox" Or TypeName(MyControl) = "ComboBox" Then
For i = 0 To 6
If Right(MyControl.Name, 1) = i + 1 Then MyRange.Offset(, i) = MyControl.Text
Next
End If
Next
ListBox1.List = Range(Sheet1.[A2], Sheet1.[A65536].End(xlUp)).Resize(, 7).Value
End Sub