我有工作表1的名字范围。我有一个味精框输入,可以单击引用该值的单元格。如果匹配,它将找到该值在工作表2的C列中的位置。它可以按我希望的方式工作,但是我需要弄清楚如何突出显示 whole 行。另外,是否可以滚动到索引以确保将其从工作表2向下移动到突出显示该行的位置?
代码:
Sub tgr()
Dim rFound As Range
Dim lemployee As String
Dim sh As Worksheet
Dim rw As Long
Dim matched As Boolean
lemployee = Application.InputBox("Please selct an employee", "Employee Name", Type:=2)
If lemployee = "False" Then Exit Sub
Set sh = Sheets("Sheet1")
rw = 2
With ThisWorkbook.Worksheets("Sheet2").Columns("C")
Set rFound = .Find(lemployee, .Cells(.Cells.Count), xlValues, xlWhole)
If ThisWorkbook.Worksheets("Sheet2").Cells(rFound.Row, 3).Value = lemployee Then
.Cells(rFound.Row).Interior.Color = VBA.RGB(255, 255, 0)
End If
End With
End Sub
编辑:至于滚动,我只需要类似以下内容:
Application. Goto ActiveCell.EntireRow,True
答案 0 :(得分:2)
类似这样的东西:
With ThisWorkbook.Worksheets("Sheet2").Columns("C")
Set rFound = .Find(lemployee, .Cells(.Cells.Count), xlValues, xlWhole)
If Not rFound Is Nothing Then
rFound.EntireRow.Interior.Color = VBA.RGB(255, 255, 0)
Application.Goto rFound
End If
End With