Search code examples
vbaexcelexcel-2007

make one cell value 0 if other cell value > 0 using excel


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

if i write something on Cell.(A1)= 0 it make cell(B1) =0 automatically.
if i write something on Cell.(B1)= 0 it make cell(A1) =0 automatically.


Solution

  • Let suppose that you want base values in B column on values on A value.

    Then your code should look like this:

    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