如果其他单元格值> 0,则使用excel创build一个单元格值为0

AB 0 1 2 0 3 0 0 4 5 0 

如果我在单元格上写一些东西(A1)= 0,它会自动使单元格(B1)= 0。
如果我在Cell上写了一些东西(B1)= 0,它会自动使cell(A1)= 0。

让我们假设你需要B列中的A值的基值。

那么你的代码应该是这样的:

 Sub fillValues() Dim i, k As Integer k = Cells(1, 1).CurrentRegion.Rows.Count 'determine last row For i = 1 To k If Cells(i, 1).Value > 0 Then Cells(i, 2).Value = 0 End If Next i End Sub 

如果您希望在A:B列的任意位置input值0自动调整值,则需要在Worksheet_Change事件中使用代码。

注意:不确定如果您想要将其中一个单元格更改为00时将另一个单元格0打开,则不确定。

 Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = False If Not Intersect(Target, Columns("A:B")) Is Nothing Then ' check if a cell in Columns A:B is changed If Target.Value = 0 Then '<-- if the value changed is 0 ' option 2 to your post 'If Target.Value > 0 Then '<-- if the value changed is > 0 Select Case Target.Column '<-- check which column modifed, A or B Case 1 Target.Offset(, 1).Value = 0 Case 2 Target.Offset(, -1).Value = 0 End Select End If End If Application.EnableEvents = True End Sub