|
-
Jan 26th, 2004, 10:01 AM
#1
Thread Starter
New Member
[vb] - Make this shorter?
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
-
Jan 26th, 2004, 10:06 AM
#2
You can place the KeyAscii test in a separate function and just call this function.
Saves you two lines per on_key function.
You can also make the main part shorter, but at a rather heavy speed impact, and I don't think it's worth it unless it's likey that more columns get added.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|