Can i make this shorter?
VB Code:
Private Sub OK_Click() Sheets("Details").Activate If IsEmpty(Range("B2")) Then Row = 2 Else Row = Range("B1").End(xlDown).Row + 1 End If Cells(Row, 1) = txtFor.Text If IsEmpty(Range("C2")) Then Row = 2 Else Row = Range("C1").End(xlDown).Row + 1 End If Cells(Row, 2) = txtSur.Text If IsEmpty(Range("D2")) Then Row = 2 Else Row = Range("D1").End(xlDown).Row + 1 End If Cells(Row, 3) = txtAge.Value If IsEmpty(Range("E2")) Then Row = 2 Else Row = Range("E1").End(xlDown).Row + 1 End If Cells(Row, 4) = txtMob.Value If IsEmpty(Range("F2")) Then Row = 2 Else Row = Range("F1").End(xlDown).Row + 1 End If Cells(Row, 5) = txtHom.Value Unload Me End Sub 'new sub Private Sub txtAge_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub 'new sub Private Sub txtMob_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub 'new sub Private Sub txtHom_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub 'new sub Private Sub txtSur_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And KeyAscii < 65 Or KeyAscii > 90 Then KeyAscii = 0 End If End Sub 'new sub Private Sub txtFor_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And KeyAscii < 65 Or KeyAscii > 90 Then KeyAscii = 0 End If End Sub




Reply With Quote