开发者

Excel Looping through a table and deleting a specific cell

I am trying to loop through a table in excel. The table ranges from (A1: C50). Column A is Serial Number, Column B is income, Column C is Total.

I have a cell D10 which is a random Serial number. I want to loop through the table and check if the serial number in the table corresponds with my serial number in D10 and delete the correspongding income cell for that row. Is it possible by using VBA.

Thank yo开发者_StackOverflow社区u so much in advance.


For x = 1 To 50
  If Cells(x, 1).Value = Cells(10, 4).Value Then
    Cells(x, 2).Value = ""
  End If
Next x


Sub DeleteIncome()
    Dim serialNumbers as Range, cl as Range, randomSerialNumber as Range
    Set serialNumbers = Range("A1:A50")
    Set randomSerialNumber = Range("D10")

    For each cl in serialNumbers
        If cl.value = randomSerialNumber.value Then
           cl.offset(0,1) = ""
        End if
    Next cl
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜