Full code in UserForm2 module:
Option Explicit
Private Sub ComboBox1_Change()
If Me.ComboBox1.ListIndex < 0 Then Exit Sub
With MyRange.Cells(1).Offset(ComboBox1.ListIndex)
TextBox1.Value = .Offset(, 1).Value
TextBox2.Value = .Offset(, 2).Value
TextBox3.Value = .Offset(, 3).Value
TextBox4.Value = .Offset(, 4).Value
TextBox5.Value = .Offset(, 5).Value
TextBox6.Value = .Offset(, 6).Value
TextBox7.Value = .Offset(, 7).Value
TextBox8.Value = .Offset(, 8).Value
TextBox9.Value = .Offset(, 9).Value
TextBox10.Value = .Offset(, 10).Value
TextBox11.Value = .Offset(, 11).Value
TextBox12.Value = .Offset(, 12).Value
TextBox13.Value = .Offset(, 13).Value
TextBox14.Value = .Offset(, 14).Value
TextBox15.Value = .Offset(, 15).Value
TextBox16.Value = .Offset(, 16).Value
TextBox17.Value = .Offset(, 17).Value
TextBox18.Value = .Offset(, 18).Value
End With
End Sub
Private Sub CommandButton1_Click()
If Me.ComboBox1.ListIndex < 0 Then Exit Sub
With MyRange.Cells(1).Offset(ComboBox1.ListIndex)
.Offset(, 0).Value = ComboBox1.Value
.Offset(, 1).Value = TextBox1.Value
.Offset(, 2).Value = TextBox2.Value
.Offset(, 3).Value = TextBox3.Value
.Offset(, 4).Value = TextBox4.Value
.Offset(, 5).Value = TextBox5.Value
.Offset(, 6).Value = TextBox6.Value
.Offset(, 7).Value = TextBox7.Value
.Offset(, 8).Value = TextBox8.Value
.Offset(, 9).Value = TextBox9.Value
.Offset(, 10).Value = TextBox10.Value
.Offset(, 11).Value = TextBox11.Value
.Offset(, 12).Value = TextBox12.Value
.Offset(, 13).Value = TextBox13.Value
.Offset(, 14).Value = TextBox14.Value
.Offset(, 15).Value = TextBox15.Value
.Offset(, 16).Value = TextBox16.Value
.Offset(, 17).Value = TextBox17.Value
.Offset(, 18).Value = TextBox18.Value
End With
Unload Me
MsgBox "Record Updated"
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim MyRng As Range
ComboBox1.Clear
Set MyRng = MyRange
If Not MyRng Is Nothing Then
If MyRng.Count = 1 Then
ComboBox1.AddItem MyRng.Value
Else
ComboBox1.List = MyRange.Value
End If
End If
End Sub
Function MyRange() As Range
Dim LastRange As Range
With Sheet1
Set LastRange = .Cells(Rows.Count, "A").End(xlUp)
If LastRange.Row > 2 Then
Set MyRange = .Range(.[a3], LastRange)
End If
End With
End Function
Artik
Bookmarks