ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 890|回复: 3

求元老们做个模糊查询与筛选的代码

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-7-21 19:43 | 显示全部楼层 |阅读模式
先谢谢各位元老了

模糊筛选制作.zip

34.84 KB, 下载次数: 7

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-7-22 21:29 | 显示全部楼层
以下的这些代码都是从这个网站找到的,感觉很好,但我不会运用与更改,懂代码的高人,帮个忙把这些代码做到“模糊筛选制作”内,在下感谢了。
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, _
        ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
        
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 8 Then Exit Sub     
    Dim lHwnd As Long
    Dim lDC As Long
    Dim lCaps As Long
    Dim lngLeft As Long
    Dim lngTop As Long
    Dim sngPiexlToPiont As Single
    Const lLogPixelsX = 88
    lDC = GetDC(0)
    lCaps = GetDeviceCaps(lDC, lLogPixelsX)
    sngPiexlToPiont = 72 / lCaps * (100 / ActiveWindow.Zoom)
    lngLeft = CLng(ActiveWindow.PointsToScreenPixelsX(0) + (Target.Offset(1, 1).Left / sngPiexlToPiont))     '
    lngTop = CLng(ActiveWindow.PointsToScreenPixelsY(0) + (Target.Offset(1, 1).Top / sngPiexlToPiont))       '
    UserForm1.StartUpPosition = 0
    lHwnd = FindWindow(vbNullString, UserForm1.Caption)
    MoveWindow lHwnd, lngLeft, lngTop, 360, 360, True
    UserForm1.Show
    End Sub




Private Sub ListBox1_Click()
    ActiveCell.Value = ListBox1.Value
   Me.ListBox1.Visible = False
    Unload Me
End Sub

Private Sub TextBox1_Change()
arr = Sheet3.[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(arr)
If InStr(arr(i, 1), TextBox1.Text) > 0 Then
n = n + 1
brr(n, 1) = arr(i, 1)
End If
Next i
ListBox1.List = brr
End Sub

Private Sub UserForm_Initialize()
' ListBox1.List = Range("sheet3!a1:a" & Worksheets("sheet3").Cells(Worksheets("sheet3").Rows.Count, 1).End(3).Row).Value
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-7-22 21:30 | 显示全部楼层
以下的这些代码都是从这个网站找到的,感觉很好,但我不会运用与更改,懂代码的高人,帮个忙把这些代码做到“模糊筛选制作”内,在下感谢了。
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, _
        ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
        
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 8 Then Exit Sub     
    Dim lHwnd As Long
    Dim lDC As Long
    Dim lCaps As Long
    Dim lngLeft As Long
    Dim lngTop As Long
    Dim sngPiexlToPiont As Single
    Const lLogPixelsX = 88
    lDC = GetDC(0)
    lCaps = GetDeviceCaps(lDC, lLogPixelsX)
    sngPiexlToPiont = 72 / lCaps * (100 / ActiveWindow.Zoom)
    lngLeft = CLng(ActiveWindow.PointsToScreenPixelsX(0) + (Target.Offset(1, 1).Left / sngPiexlToPiont))     '
    lngTop = CLng(ActiveWindow.PointsToScreenPixelsY(0) + (Target.Offset(1, 1).Top / sngPiexlToPiont))       '
    UserForm1.StartUpPosition = 0
    lHwnd = FindWindow(vbNullString, UserForm1.Caption)
    MoveWindow lHwnd, lngLeft, lngTop, 360, 360, True
    UserForm1.Show
    End Sub




Private Sub ListBox1_Click()
    ActiveCell.Value = ListBox1.Value
   Me.ListBox1.Visible = False
    Unload Me
End Sub

Private Sub TextBox1_Change()
arr = Sheet3.[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(arr)
If InStr(arr(i, 1), TextBox1.Text) > 0 Then
n = n + 1
brr(n, 1) = arr(i, 1)
End If
Next i
ListBox1.List = brr
End Sub

Private Sub UserForm_Initialize()
' ListBox1.List = Range("sheet3!a1:a" & Worksheets("sheet3").Cells(Worksheets("sheet3").Rows.Count, 1).End(3).Row).Value
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-7-22 21:31 | 显示全部楼层
以下的这些代码都是从这个网站找到的,感觉很好,但我不会运用与更改,懂代码的高人,帮个忙把这些代码做到“模糊筛选制作”内,在下感谢了。
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, _
        ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
        
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 8 Then Exit Sub     
    Dim lHwnd As Long
    Dim lDC As Long
    Dim lCaps As Long
    Dim lngLeft As Long
    Dim lngTop As Long
    Dim sngPiexlToPiont As Single
    Const lLogPixelsX = 88
    lDC = GetDC(0)
    lCaps = GetDeviceCaps(lDC, lLogPixelsX)
    sngPiexlToPiont = 72 / lCaps * (100 / ActiveWindow.Zoom)
    lngLeft = CLng(ActiveWindow.PointsToScreenPixelsX(0) + (Target.Offset(1, 1).Left / sngPiexlToPiont))     '
    lngTop = CLng(ActiveWindow.PointsToScreenPixelsY(0) + (Target.Offset(1, 1).Top / sngPiexlToPiont))       '
    UserForm1.StartUpPosition = 0
    lHwnd = FindWindow(vbNullString, UserForm1.Caption)
    MoveWindow lHwnd, lngLeft, lngTop, 360, 360, True
    UserForm1.Show
    End Sub




Private Sub ListBox1_Click()
    ActiveCell.Value = ListBox1.Value
   Me.ListBox1.Visible = False
    Unload Me
End Sub

Private Sub TextBox1_Change()
arr = Sheet3.[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(arr)
If InStr(arr(i, 1), TextBox1.Text) > 0 Then
n = n + 1
brr(n, 1) = arr(i, 1)
End If
Next i
ListBox1.List = brr
End Sub

Private Sub UserForm_Initialize()
' ListBox1.List = Range("sheet3!a1:a" & Worksheets("sheet3").Cells(Worksheets("sheet3").Rows.Count, 1).End(3).Row).Value
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

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

GMT+8, 2024-4-25 22:15 , Processed in 0.029163 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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