VBA code Using Data table to populate the userform
<p>So I am doing some coding for the payroll application. When I run the macro and enter EmployeeNumber in textbox1, I get sent to debugging and third row of code "c=application.worksheet...." is highlighted in yellow. Basically, when I enter employee number in textbox 1, the subsequent information of that employee should get populated by itself. Can someone please tell me what I am doing wrong in the code below?</p>

<pre><code>Private Sub CommandButton1_Click()
Me.TextBox2.Enabled = True
Me.TextBox3.Enabled = True
Me.TextBox4.Enabled = True
Me.TextBox5.Enabled = True
Me.TextBox6.Enabled = True
Me.CommandButton2.Visible = True
Me.CommandButton1.Visible = False
End Sub

Private Sub CommandButton2_Click()
m = MsgBox("Do You Want To Update Employee Information?", vbQuestion + vbYesNo, "Confirm Update")

If m = vbNo Then Exit Sub


EmployeeNumber = Val(Me.TextBox1.Value)

c = Application.WorksheetFunction.CountIf(MasterData.Range("A:A"),  EmployeeNumber)
If c = 0 Then Exit Sub

r = Application.WorksheetFunction.Match(EmployeeNumber,   MasterData.Range("A:A"), 0)
MasterData.Range("B" &amp; r).Value = Me.TextBox2.Value
MasterData.Range("C" &amp; r).Value = Me.TextBox3.Value
MasterData.Range("D" &amp; r).Value = Me.TextBox4.Value
MasterData.Range("E" &amp; r).Value = Me.TextBox5.Value
MasterData.Range("F" &amp; r).Value = Me.TextBox6.Value

Me.TextBox2.Enabled = False
Me.TextBox3.Enabled = False
Me.TextBox4.Enabled = False
Me.TextBox5.Enabled = False
Me.TextBox6.Enabled = False
Me.CommandButton2.Visible = False
Me.CommandButton1.Visible = True
End Sub

Private Sub CommandButton3_Click()
Unload.Me
End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label5_Click()

End Sub

Private Sub TextBox1_Change()
Dim wks As Worksheet
Set wks = Worksheets("MasterData")

EmployeeNumber = Val(Me.TextBox1.Value)

c = Application.WorksheetFunction.CountIf(MasterData.Range("A:A"), EmployeeNumber)

If c = 0 Then
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Exit Sub
End If
r = Application.WorksheetFunction.Match(EmployeeNumber, MasterData.Range("A:A"), 0)

Me.TextBox2.Value = MasterData.Range("B" &amp; r).Value
Me.TextBox3.Value = MasterData.Range("C" &amp; r).Value
Me.TextBox4.Value = MasterData.Range("D" &amp; r).Value
Me.TextBox5.Value = MasterData.Range("E" &amp; r).Value
Me.TextBox6.Value = MasterData.Range("F" &amp; r).Value


End Sub

Private Sub UserForm_Click()

End Sub
</code></pre>