答案 0 :(得分:0)
Sub MyReplace()
Dim rw As Long
With ActiveSheet
On Error Resume Next
rw = Application.WorksheetFunction.Match(.Range("B13"), .Range("B4:B7"), 0)
On Error GoTo 0
If rw > 0 Then
.Range("C" & rw + .Range("B4:B7").Row - 1).Value = .Range("C13")
Else
MsgBox "Name not found in range"
End If
End With
End Sub
答案 1 :(得分:0)
没有错误处理程序:
Sub F()
With [B3:C7]
.Cells(WorksheetFunction.Match([B13], .Columns(1), 0), 2) = [C13]
End With
End Sub
答案 2 :(得分:0)
如果该按钮是ActiveX
控件,您可以点击工作表模块CommandButton_Click
事件,并将以下子项添加到工作表本身。
Option Explicit
Private Sub CommandButton1_Click() 'Change CommandButton1 to the actual name of your button
Dim i As Long
Dim blnRecorded As Boolean
With Me
For i = 4 To .Cells(4, 2).End(xlDown).Row
If .Cells(i, 4) = .Cells(4, 3) Then
.Cells(i, 5) = .Cells(4, 4)
blnRecorded = True
Exit For
End If
Next i
If Not blnRecorded Then
MsgBox "The typed name does not match any employee in the table"
End If
End With
End Sub