Hi,
Replace all your code with the following
Public MyRange As Range
Public ws As Worksheet
Public Idx As Long
Private Sub ComboBox1_Change()
Idx = Me.ComboBox1.ListIndex + 1
If Idx = 0 Then
Me.TextBox1.Value = ""
Else
Me.TextBox1.Value = Application.Index(MyRange.Value, Idx, 2)
End If
End Sub
Private Sub CommandButton1_Click()
With MyRange.Cells(1, 1)
If Idx = 0 Then
Idx = Me.ComboBox1.ListCount
.Offset(Idx).Value = Me.ComboBox1
.Offset(Idx, 1).Value = Me.TextBox1
Set MyRange = ws.Range("A2:B" & ws.Range("a" & Rows.Count).End(xlUp).Row)
Me.ComboBox1.List = Application.Index(MyRange.Value, 0, 1)
Else
.Offset(Idx - 1).Value = Me.ComboBox1
.Offset(Idx - 1, 1).Value = Me.TextBox1
End If
End With
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Set ws = Sheets("Sheet1")
Set MyRange = ws.Range("A2:B" & ws.Range("a" & Rows.Count).End(xlUp).Row)
Me.ComboBox1.List = Application.Index(MyRange.Value, 0, 1)
End Sub
HTH
Bookmarks