|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub Test()
- Dim shSource As Worksheet, shResult As Worksheet
- Dim lngRow As Long, arrSource As Variant, arrTemp As Variant
- Dim strTemp As String, strFind As String, lngID As Long
-
- Set shSource = Sheets("明细")
- Set shResult = Sheets("查询")
-
- strFind = Trim(shResult.Range("P2").Value)
- If strFind = "" Then
- MsgBox "请输入查询内容"
- Exit Sub
- End If
-
- lngRow = shSource.Range("A" & Rows.Count).End(xlUp).Row
- arrSource = shSource.Range("A4:N" & lngRow)
-
- shResult.Range("A4:N" & Rows.Count).Clear
- lngID = 4
-
- For lngRow = LBound(arrSource) To UBound(arrSource)
- arrTemp = Application.WorksheetFunction.Index(arrSource, lngRow, 0)
- strTemp = Join(arrTemp, "|")
- If InStr(strTemp, strFind) > 0 Then
- shResult.Range("A" & lngID).Resize(1, UBound(arrTemp)) = arrTemp
- lngID = lngID + 1
- End If
- Next
-
- End Sub
复制代码 |
|