这个EXCEL函数VBA怎么弄代码?求一个!

2025-03-23 11:25:18
推荐回答(3个)
回答1:

测试通过,确保正确运行的代码如下:

Option Explicit
Sub x()
    Dim i, j, n
    n = ActiveSheet.UsedRange.Rows.Count
    For i = 1 To n
        If Cells(i, "A") = 1 Then
            For j = n To 1 Step -1
                If Cells(j, "C") = Cells(i, "B") Then Cells(j, "C").Delete (xlShiftUp)
            Next j
        End If
    Next i
End Sub

回答2:

Sub 清除()
For i = 1 To [a65536].End(3).Row
    For k = 1 To [c65536].End(3).Row
        If Cells(i, 1) = 1 Then
            If Cells(k, 3) = Cells(i, 2) Then Cells(k, 3).Delete
        End If
    Next
Next
End Sub

回答3:

Sub test()
    Dim i, j As Integer
    For i = 1 To ActiveSheet.UsedRange.Rows.Count
        If Range("A" & i) = 1 Then'这行的A就是判定是否等于1的列
            For j = 1 To ActiveSheet.UsedRange.Rows.Count
                If Range("C" & j).Value = Range("B" & i).Value Then Range("C" & j).Value = "" '这行的C就是要判定的列
            Next
        End If
    Next
End Sub