Sub 替换()
Dim rg, cel As Object
Set rg = Application.InputBox("请选择第一列姓名", , "range", , , , , 8)
For Each cel In rg
If cel = "张三" And cel.Offset(, 1) = "张三丰" Then cel.Offset(, 1) = cel.Offset(, 2): cel.Offset(, 2) = "三四"
If cel = "李四" And cel.Offset(, 1) = "李四通" Then cel.Offset(, 1) = cel.Offset(, 2): cel.Offset(, 2) = "三四"
Next
End Sub
点开图片查看
写好了,我的自动识别有几行,按钮执行就行了。
Private Sub CommandButton1_Click()
Dim i As Integer, l As Long, rng As Range
l = Cells(Rows.Count, "a").End(xlUp).Row
For i = 2 To l
Set rng = Cells(i, 2).Find(Cells(i, 1), LookIn:=xlValues)
If Not rng Is Nothing Then
Cells(i, 2) = Cells(i, 3)
Cells(i, 3) = "三四"
End If
Next
End Sub
问题不清晰 必要时截图说明