|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2011-10-28 10:02
|
显示全部楼层
Private Sub CommandButton1_Click()
Sheet1.Select
Dim aa$, bb$, aa1$, n%, r1
aa = TextBox1.Text
bb = TextBox2.Text
aa1 = Left(aa, 4)
Set r1 = Range("e:e").Find(aa1)
If Not r1 Is Nothing Then
n = r1.Row
If Cells(n, 5).Offset(1, 0) = "" Then
Cells(n + 1, 5) = aa
Cells(n + 1, 6) = bb
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
ElseIf Len(Cells(n, 5).Offset(1, 0)) = 4 Then
Range(Cells(n + 1, 4), Cells(n + 1, 6)).Select
Selection.Insert Shift:=xlDown
Cells(n + 1, 5) = aa
Cells(n + 1, 6) = bb
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
Else
Do
n = n + 1
If Val(aa) < Cells(n, 5) Then
Range(Cells(n, 4), Cells(n, 6)).Select
Selection.Insert Shift:=xlDown
Cells(n, 5) = aa
Cells(n, 6) = bb
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
Else
End If
Loop While Len(Cells(n + 1, 5)) <> 4
Range(Cells(n + 1, 4), Cells(n + 1, 6)).Select
Selection.Insert Shift:=xlDown
Cells(n + 1, 5) = aa
Cells(n + 1, 6) = bb
TextBox1.Text = ""
TextBox2.Text = ""
Exit Sub
End If
End If
End Sub |
|