Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1593|回复: 4

【求助】请高手详解代码意思

[复制链接]
发表于 2011-10-26 11:34 | 显示全部楼层 |阅读模式
代码详解.rar (12.59 KB, 下载次数: 11)
发表于 2011-10-26 12:30 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 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
回复

使用道具 举报

 楼主| 发表于 2011-10-28 10:02 | 显示全部楼层
将代码贴出!
回复

使用道具 举报

 楼主| 发表于 2011-10-30 09:34 | 显示全部楼层
期待中……      
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-7-8 03:39 , Processed in 0.117447 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表