|
Private Sub ListView1_Click()
Dim n As Integer, istr As String, i As Integer, r As Integer
On Error Resume Next
n = ListView1.SelectedItem.Index
If n < 0 Then Exit Sub
istr = Trim(ListView1.ListItems(n).Text)
With Sheets("PW") 'Sheet1
r = .Range("b" & Rows.Count).End(xlUp).Row
i = .[a2].Resize(r, 1).Find(istr).Row
If i < 2 Then Exit Sub
.Range(Cells(i, 1), Cells(i, 6)).Select
End With
Dim n As Integer, istr As String, i As Integer, r As Integer
On Error Resume Next '若出错则运行下一句
n = ListView1.SelectedItem.Index '获取被点击的索引号
If n < 0 Then Exit Sub '若索引号<0则退出
istr = Trim(ListView1.ListItems(n).Text) '获取被点击行的首列内容
With Sheets("PW") 'Sheet1
r = .Range("b" & Rows.Count).End(xlUp).Row '获取工作表“PW”的B列最后一行行号
i = .[a2].Resize(r, 1).Find(istr).Row '在工作表A列A2及以下有数据范围查找变量istr的内容所在行号
If i < 2 Then Exit Sub '<2则退出
.Range(Cells(i, 1), Cells(i, 6)).Select '找到的行中1~6列激活
End With
|
|