Excel VBA:搜索和替换If / Conditional

时间:2015-02-18 10:05:20

标签: excel vba excel-vba

我们可以用VBA吗?

如果A列上的文字=“学生”,B栏上的文字=“John”,则将B文本替换为“John Paul”。

谢谢。

1 个答案:

答案 0 :(得分:-1)

回答我的问题。适合我:

Sub ChangeJohn()

Dim x As Integer
Dim i As Integer

x = Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To x

If Range("A" & i).Value = "Student" Then
    If Range("B" & i).Value = "John" Then
        Range("B" & i).Value = "John Paul"
    End If
End If

Next i

End Sub