|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 皮皮坦克 于 2018-8-6 15:19 编辑
代码可以正常运行,但是当搜索的关键字为数字时,可以检索到时,只返回了标题行,这是为什么?
Sub 查找关键字并复制到新表中()
Dim rng As Range, arr1(), lh, gjz, i, j, k, brr(), czf
gjz = InputBox("", "请输入查询条件", "关键字只在一列出现,不能同时出现在多列")
arr1 = Sheet1.Range("a1").CurrentRegion
Set czf = Range(Cells(1, 1), Cells(UBound(arr1), UBound(arr1, 2))).Find(gjz, LookIn:=xlValues)
If Not czf Is Nothing Then
lh = czf.Column
ReDim brr(1 To UBound(arr1), 1 To UBound(arr1, 2))
For i = 1 To UBound(arr1)
If i = 1 Or arr1(i, lh) = gjz Then
j = j + 1
For k = 1 To UBound(arr1, 2)
brr(j, k) = arr1(i, k)
Next
End If
Next
Workbooks("胜利在望").Worksheets("sheet3").Range("a1").Resize(j, UBound(brr, 2)) = brr
Else: MsgBox "未找到"
End If
End Sub
|
|