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

时间:2017-02-28 10:56:19

标签: excel vba excel-vba excel-2007

A   B
0   1
2   0
3   0
0   4
5   0

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

2 个答案:

答案 0 :(得分:1)

假设您希望B列中的基值值为A值上的值。

然后你的代码应该是这样的:

Visualize: Fielddata is disabled on text fields by default. Set fielddata=true on [docker.container.name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.

Visualize: Fielddata is disabled on text fields by default. Set fielddata=true on [docker.container.id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.

Visualize: Fielddata is disabled on text fields by default. Set fielddata=true on [docker.container.image] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.

答案 1 :(得分:1)

如果您希望在A:B列的任何位置输入值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