ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: yagi2008

[原创] 从实例学VBA编程

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2009-3-4 04:41 | 显示全部楼层
我靠  终于抓住楼主了
从入门看到现在  都凌晨5点了
你太牛了
我等不急啊
如饥似渴

TA的精华主题

TA的得分主题

发表于 2009-3-4 08:15 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
呵呵,老师依然的是那么的幽默风趣!~~呼~啦~呼~啦~,请给我领三瓶酱油~我是来打酱油的!!!!

TA的精华主题

TA的得分主题

发表于 2009-3-4 08:37 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-3-4 08:50 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-3-4 09:08 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-3-4 09:14 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
感谢楼主,百忙中给我们讲解!!

TA的精华主题

TA的得分主题

发表于 2009-3-4 12:46 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-3-4 17:23 | 显示全部楼层
Private Sub ComboBox1_AfterUpdate() N&G; `  
    Dim renshu As Integer '人数 %'MR;hQsd8  
    Dim mybool As Boolean vMYEP_lhK,  
    renshu = 3 V!f' O@p[  
    mybool = 1 rT'<6]`  
    Do While Cells(renshu, 1) <> "" F~l:W QAj  
        If Me.ComboBox1.Text = Cells(renshu, 1) Then 3J[ 5^  
            Me.ComboBox2.Caption = Cells(renshu, 2) ug?#Oa  
            Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3)) 9u1Fk'cxG,  
            Me.TextBox2 = Cells(renshu, 6) ]g]~!":  
            Me.TextBox3 = Cells(renshu, 7) 2f2.;D5g_'  
            Me.TextBox4 = Cells(renshu, 9) ?mh0^G  
            Me.TextBox5 = Cells(renshu, 14) =UV=F/Af^  
            Me.TextBox6 = Cells(renshu, 20).Text y*j8OA.S  
            Me.TextBox7 = Cells(renshu, 21) e ls&_BPE  
            Me.TextBox8 = Cells(renshu, 12) IWnyqt(k  
            Me.TextBox9 = Cells(renshu, 16) rm!.J0 X  
            Me.TextBox10 = Cells(renshu, 13) wi S8S{K5  
            mybool = 0 7J$Yd976  
            Exit Do % ^&D,  
        End If y:dwx*Q9I  
        renshu = renshu + 1 0@2pw2{Ru  
    Loop b* o,re)Dj  
    If mybool Then }9>X M  
        MsgBox "无此工号" ;/ao3Q   
        Me.ComboBox1.Text = Cells(3, 1) $:<G=  
        Me.ComboBox2.Caption = Cells(3, 2) q pFzK  
        Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3)) Zbjj>*2%^  
            Me.TextBox2 = Cells(renshu, 6) p>4bj>Ql  
            Me.TextBox3 = Cells(renshu, 7) qYR+qSAJP  
            Me.TextBox4 = Cells(renshu, 9) k<\]={ |=  
            Me.TextBox5 = Cells(renshu, 14) e3{L%rQE  
            Me.TextBox6 = Cells(renshu, 20).Text &<%U7?{~  
            Me.TextBox7 = Cells(renshu, 21) -}r(75C  
            Me.TextBox8 = Cells(renshu, 12) xn)r6  
            Me.TextBox9 = Cells(renshu, 16) k0R;1lZ0n  
            Me.TextBox10 = Cells(renshu, 13) T+|V;nP.  
    End If =AJ I3 'x  
End Sub _G5M Q%z  
Private Sub ComboBox1_Change() @OPyT  
    Dim renshu As Integer '人数 to*<W,I  
    renshu = 3 IRQ3>4hI  
    Do While Cells(renshu, 1) <> "" CfnRcnms  
        If Me.ComboBox1.Text = Cells(renshu, 1) Then -/ #tQ~{gs  
            Me.ComboBox2.Caption = Cells(renshu, 2) ^R4eW|H  
            Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3)) zorTZ #5  
            Me.TextBox2 = Cells(renshu, 6) ^ok;<fJ  
            Me.TextBox3 = Cells(renshu, 7) <WGl4#(k  
            Me.TextBox4 = Cells(renshu, 9) kM?p>V6  
            Me.TextBox5 = Cells(renshu, 14) S:"t]gbF =  
            Me.TextBox6 = Cells(renshu, 20).Text w{"GA ~=  
            Me.TextBox7 = Cells(renshu, 21) b_ |  
            Me.TextBox8 = Cells(renshu, 12) 7o+!Gts]  
            Me.TextBox9 = Cells(renshu, 16) "ppT<8Qi'  
            Me.TextBox10 = Cells(renshu, 13) D4r5wc%  
            Exit Do FZ/l T-"  
        End If Sn/~R|3XA7  
        renshu = renshu + 1 QW f)5S  
    Loop Tf"DpA!_  
End Sub DwZt.*  
Private Sub CommandButton1_Click() oA~m*|  
    Dim renshu As Integer '人数 q9oF8&O,  
    renshu = 3 As (C8C<  
    Do While Cells(renshu, 1) <> "" 9kP!O_  
        If Me.ComboBox1.Text = Cells(renshu, 1) Then K. R2)o`  
            Cells(renshu, 6) = Me.TextBox2.Value 64 \ZOG\,  
            Cells(renshu, 7) = Me.TextBox3.Text n a2"Sy=Yi  
            Cells(renshu, 9) = Me.TextBox4.Value ;?2vW8{p<  
            Cells(renshu, 14) = Me.TextBox5.Value VJCh5t*  
            Cells(renshu, 20) = Me.TextBox6.Value H8K<.RY  
            Cells(renshu, 21) = Me.TextBox7.Text 7"xd'\c@  
            Cells(renshu, 12) = Me.TextBox8.Value Mn~A;=%qF  
            Cells(renshu, 16) = Me.TextBox9.Value *!9/`zW  
            Cells(renshu, 13) = Me.TextBox10.Value @mJN  
            Exit Do Ip4NkUI3T  
        End If kM3BP& 3m1  
        renshu = renshu + 1 L''0`a. +S  
    Loop UWn}0:6t  
    renshu = renshu + 1 <YeF?$S}  
    If renshu >= a Then Exit Sub XFu@XUk!K  
    Me.ComboBox1.Text = Cells(renshu, 1) z}bnw2d]  
    Me.ComboBox2.Caption = Cells(renshu, 2) >>$IHz4Z"  
    Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3)) INbjk;k  
            Me.TextBox2 = Cells(renshu, 6) 0dcXgP  
            Me.TextBox3 = Cells(renshu, 7) o~-X7)]  
            Me.TextBox4 = Cells(renshu, 9) ;2@sn+@  
            Me.TextBox5 = Cells(renshu, 14) 9)l_(*F  
            Me.TextBox6 = Cells(renshu, 20).Text "{x~j \<  
            Me.TextBox7 = Cells(renshu, 21) ]R4)FH|><  
            Me.TextBox8 = Cells(renshu, 12) amBz75N{  
            Me.TextBox9 = Cells(renshu, 16) 3-mw-;.  
            Me.TextBox10 = Cells(renshu, 13) l#~Fe D  
    If Me.Label2.Caption = "喷油部" Then Me.TextBox5.SetFocus Else Me.TextBox2.SetFocus 4*+EUJ|  
End Sub }a9C /t3  
       请问大家:这里的 Me. 是什么意思?在什么时候用呀?这里若不用Me. ,可以吗?

TA的精华主题

TA的得分主题

发表于 2009-3-4 17:24 | 显示全部楼层
Private Sub ComboBox1_AfterUpdate()
    Dim renshu As Integer '人数
    Dim mybool As Boolean
    renshu = 3
    mybool = 1
    Do While Cells(renshu, 1) <> ""
        If Me.ComboBox1.Text = Cells(renshu, 1) Then
            Me.ComboBox2.Caption = Cells(renshu, 2)
            Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3))
            Me.TextBox2 = Cells(renshu, 6)
            Me.TextBox3 = Cells(renshu, 7)
            Me.TextBox4 = Cells(renshu, 9)
            Me.TextBox5 = Cells(renshu, 14)
            Me.TextBox6 = Cells(renshu, 20).Text
            Me.TextBox7 = Cells(renshu, 21)
            Me.TextBox8 = Cells(renshu, 12)
            Me.TextBox9 = Cells(renshu, 16)
            Me.TextBox10 = Cells(renshu, 13)
            mybool = 0
            Exit Do
        End If
        renshu = renshu + 1
    Loop
    If mybool Then
        MsgBox "无此工号"
        Me.ComboBox1.Text = Cells(3, 1)
        Me.ComboBox2.Caption = Cells(3, 2)
        Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3))
            Me.TextBox2 = Cells(renshu, 6)
            Me.TextBox3 = Cells(renshu, 7)
            Me.TextBox4 = Cells(renshu, 9)
            Me.TextBox5 = Cells(renshu, 14)
            Me.TextBox6 = Cells(renshu, 20).Text
            Me.TextBox7 = Cells(renshu, 21)
            Me.TextBox8 = Cells(renshu, 12)
            Me.TextBox9 = Cells(renshu, 16)
            Me.TextBox10 = Cells(renshu, 13)
    End If
End Sub
Private Sub ComboBox1_Change()
    Dim renshu As Integer '人数
    renshu = 3
    Do While Cells(renshu, 1) <> ""
        If Me.ComboBox1.Text = Cells(renshu, 1) Then
            Me.ComboBox2.Caption = Cells(renshu, 2)
            Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3))
            Me.TextBox2 = Cells(renshu, 6)
            Me.TextBox3 = Cells(renshu, 7)
            Me.TextBox4 = Cells(renshu, 9)
            Me.TextBox5 = Cells(renshu, 14)
            Me.TextBox6 = Cells(renshu, 20).Text
            Me.TextBox7 = Cells(renshu, 21)
            Me.TextBox8 = Cells(renshu, 12)
            Me.TextBox9 = Cells(renshu, 16)
            Me.TextBox10 = Cells(renshu, 13)
            Exit Do
        End If
        renshu = renshu + 1
    Loop
End Sub
Private Sub CommandButton1_Click()
    Dim renshu As Integer '人数
    renshu = 3
    Do While Cells(renshu, 1) <> ""
        If Me.ComboBox1.Text = Cells(renshu, 1) Then
            Cells(renshu, 6) = Me.TextBox2.Value
            Cells(renshu, 7) = Me.TextBox3.Text
            Cells(renshu, 9) = Me.TextBox4.Value
            Cells(renshu, 14) = Me.TextBox5.Value
            Cells(renshu, 20) = Me.TextBox6.Value
            Cells(renshu, 21) = Me.TextBox7.Text
            Cells(renshu, 12) = Me.TextBox8.Value
            Cells(renshu, 16) = Me.TextBox9.Value
            Cells(renshu, 13) = Me.TextBox10.Value
            Exit Do
        End If
        renshu = renshu + 1
    Loop
    renshu = renshu + 1
    If renshu >= a Then Exit Sub
    Me.ComboBox1.Text = Cells(renshu, 1)
    Me.ComboBox2.Caption = Cells(renshu, 2)
    Me.Label2.Caption = dept(Left$(Me.ComboBox1, 3))
            Me.TextBox2 = Cells(renshu, 6)
            Me.TextBox3 = Cells(renshu, 7)
            Me.TextBox4 = Cells(renshu, 9)
            Me.TextBox5 = Cells(renshu, 14)
            Me.TextBox6 = Cells(renshu, 20).Text
            Me.TextBox7 = Cells(renshu, 21)
            Me.TextBox8 = Cells(renshu, 12)
            Me.TextBox9 = Cells(renshu, 16)
            Me.TextBox10 = Cells(renshu, 13)
    If Me.Label2.Caption = "喷油部" Then Me.TextBox5.SetFocus Else Me.TextBox2.SetFocus
End Sub
           请问大家:这里的 Me. 是什么意思?在什么时候用呀?这里若不用Me. ,可以吗?

TA的精华主题

TA的得分主题

发表于 2009-3-4 20:42 | 显示全部楼层
打个记号,好来听课,谢谢LZ分享
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-9-19 08:15 , Processed in 0.048357 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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