Excel精英培训网

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

[已解决]求大神写一个 搜索框的功能,详情见附件

[复制链接]
发表于 2017-6-5 16:02 | 显示全部楼层 |阅读模式
本帖最后由 lindadada 于 2017-6-7 10:26 编辑

求大神写一个  搜索框的功能,详情见附件


最佳答案
2017-6-5 19:12
  1. Private Sub CommandButton1_Click()
  2. Dim i, Rng As Range
  3. Dim m, n, a As Integer
  4. Application.ScreenUpdating = False
  5. Application.DisplayAlerts = False
  6. On Error Resume Next
  7. With ActiveSheet
  8.     m = [A65536].End(xlUp).Row
  9.     n = [IV9].End(xlToLeft).Column
  10.     .Cells(5, 1).Resize(1, n).Clear
  11.     sInt = Application.InputBox(Prompt:="输入账号名")
  12.     If Len(Trim(sInt)) > 0 Then
  13.         AA = sInt
  14.     Else
  15.         MsgBox Prompt:="没有输入有效的账号"
  16.         Exit Sub
  17.     End If
  18. Set Rng = .Cells(9, 1).Resize(m - 8, n).Find(AA, LookIn:=xlValues, lookat:=1)
  19.     If Not Rng Is Nothing Then
  20.         a = Rng.Row
  21.     Else
  22.         MsgBox Prompt:="您找到你要的信息"
  23.         Exit Sub
  24.     End If
  25. .Cells(a, 1).Resize(1, n).Copy
  26. .Cells(5, 1).Resize(1, n).PasteSpecial Paste:=xlPasteValues
  27. .Cells(3, 1).Resize(1, n).EntireColumn.AutoFit
  28.     With .Range("A3").CurrentRegion.Borders
  29.         .LineStyle = xlContinuous
  30.         .Weight = xlThin
  31.     End With
  32.     With .Range("A7").CurrentRegion.Borders
  33.         .LineStyle = xlContinuous
  34.         .Weight = xlThin
  35.     End With
  36.     With .Range("A3").Resize(3, n)
  37.             .VerticalAlignment = xlCenter
  38.             .HorizontalAlignment = xlCenter
  39.             .Font.Name = "微软雅黑"
  40.             .Font.Size = 11
  41.         End With
  42.         With .Range("A7").Resize(m, n)
  43.             .VerticalAlignment = xlCenter
  44.             .HorizontalAlignment = xlCenter
  45.             .Font.Name = "微软雅黑"
  46.             .Font.Size = 11
  47.         End With
  48. End With
  49. Application.ScreenUpdating = True
  50. Application.DisplayAlerts = True
  51. End Sub
复制代码
 楼主| 发表于 2017-6-5 16:04 | 显示全部楼层
附件

新建 Microsoft Office Excel 工作表 (3).zip

12.26 KB, 下载次数: 5

回复

使用道具 举报

发表于 2017-6-5 16:14 | 显示全部楼层
回复

使用道具 举报

发表于 2017-6-5 16:14 | 显示全部楼层

头像都跟我一样谁盗版谁的啊
呵呵
回复

使用道具 举报

 楼主| 发表于 2017-6-5 16:16 | 显示全部楼层
chart888 发表于 2017-6-5 16:14
头像都跟我一样谁盗版谁的啊
呵呵

大神,我盗版你的,我马上改,能不能帮忙写一个呢?
回复

使用道具 举报

 楼主| 发表于 2017-6-5 16:18 | 显示全部楼层

附件已上传

新建 Microsoft Office Excel 工作表 (3).zip

12.26 KB, 下载次数: 6

回复

使用道具 举报

发表于 2017-6-5 16:40 | 显示全部楼层
不知道你是不是这个意思随便弄了
如果需要改再说
  1. Private Sub CommandButton1_Click()

  2. Dim s, rg, sInt

  3. sInt = Application.InputBox(Prompt:="输入姓名")
  4.     If Len(Trim(sInt)) > 0 Then
  5.         AA = sInt
  6.     End If
  7. Set s = ActiveSheet.Range("A1:A" & ActiveSheet.Cells(Rows.Count, 1).End(3).Row)
  8.    For Each rg In s
  9.       If rg.Value = AA Then
  10.           a = rg.Row
  11.        End If
  12. Next
  13. ActiveSheet.Cells(a, 1).Resize(1, 5).Copy
  14. ActiveSheet.Cells(2, 7).Resize(1, 5).PasteSpecial Paste:=xlPasteValues

  15. End Sub
复制代码

测试.zip

11.94 KB, 下载次数: 11

回复

使用道具 举报

 楼主| 发表于 2017-6-5 17:08 | 显示全部楼层
chart888 发表于 2017-6-5 16:40
不知道你是不是这个意思随便弄了
如果需要改再说

大哥,能不能加下你的QQ,小妹我有点笨!
回复

使用道具 举报

 楼主| 发表于 2017-6-5 17:09 | 显示全部楼层
lindadada 发表于 2017-6-5 17:08
大哥,能不能加下你的QQ,小妹我有点笨!

我QQ 2243573864
回复

使用道具 举报

 楼主| 发表于 2017-6-5 18:08 | 显示全部楼层

就是这个

新建 Microsoft Office Excel 工作表 (3).zip

16.36 KB, 下载次数: 11

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 23:52 , Processed in 0.363197 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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