在Excel Multiple中查找和更改值

时间:2018-11-28 09:19:07

标签: excel vba

我想排序两个相同的数字,但我只想更改其中一个。

Sub replace_sales()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
    For i = 1 To 10000
        If ws.Cells(i, 1) = "1932597" Then
            ws.Cells(i, 9) = "0"
        End If
    Next i
Next ws

End Sub

1 个答案:

答案 0 :(得分:0)

在第一次匹配时放置并Exit For退出当前的ws工作表循环:

Sub replace_sales()

    Dim ws As Worksheet
    Dim i As Long

    For Each ws In ActiveWorkbook.Worksheets
        For i = 1 To 10000
            If ws.Cells(i, 1) = "1932597" Then
                ws.Cells(i, 9) = "0"
                Exit For
            End If
        Next i
    Next ws

End Sub