Excel精英培训网

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

[已解决]求助前辈帮忙加一句判断语句

[复制链接]
发表于 2015-4-14 15:11 | 显示全部楼层 |阅读模式
求助前辈帮忙加一句判断语句
最佳答案
2015-4-14 15:28
Private Sub CommandButton1_Click()
    Dim str As String
    str = UserForm1.TextBox1.Text
    Worksheets("资料").Activate
   
    If str <> "" Then
        If Range("a:a").Find(str) Is Nothing Then
            MsgBox "对不起,查无此人!!!"    ': Exit Sub    '程序终止
            UserForm1.TextBox1.Text = ""
        Else
            UserForm1.TextBox2.Text = Application.VLookup(str, Range("A:D"), 2, 0)
            UserForm1.TextBox3.Text = Application.VLookup(str, Range("A:D"), 3, 0)
            UserForm1.TextBox4.Text = Application.VLookup(str, Range("A:D"), 4, 0)
        End If
    Else
        MsgBox "对不起,姓名不能为空!!!": Exit Sub    '程序终止
    End If
End Sub

数据调用.zip

11.88 KB, 下载次数: 5

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-4-14 15:28 | 显示全部楼层    本楼为最佳答案   
Private Sub CommandButton1_Click()
    Dim str As String
    str = UserForm1.TextBox1.Text
    Worksheets("资料").Activate
   
    If str <> "" Then
        If Range("a:a").Find(str) Is Nothing Then
            MsgBox "对不起,查无此人!!!"    ': Exit Sub    '程序终止
            UserForm1.TextBox1.Text = ""
        Else
            UserForm1.TextBox2.Text = Application.VLookup(str, Range("A:D"), 2, 0)
            UserForm1.TextBox3.Text = Application.VLookup(str, Range("A:D"), 3, 0)
            UserForm1.TextBox4.Text = Application.VLookup(str, Range("A:D"), 4, 0)
        End If
    Else
        MsgBox "对不起,姓名不能为空!!!": Exit Sub    '程序终止
    End If
End Sub
回复

使用道具 举报

 楼主| 发表于 2015-4-15 15:04 | 显示全部楼层
爱疯 发表于 2015-4-14 15:28
Private Sub CommandButton1_Click()
    Dim str As String
    str = UserForm1.TextBox1.Text

谢谢前辈的解答,让我又学会了很多。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 14:08 , Processed in 0.480858 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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