Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
12
返回列表 发新帖
楼主: lindadada

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

[复制链接]
发表于 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
复制代码

测试2.zip

15.29 KB, 下载次数: 9

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-7 13:15 , Processed in 0.225980 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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