If a cell has value add a formula to neighbouring cell

I am trying to write a spreadsheet that would allow a user to enter a value say in A2 of a new row.

if the value in A2 exists (i.e., an event has taken place in A2--it changed) then I want a formula set in B2 that uses A2.

If A2 is blank, no formula will exist in B2 and the whole row remains blank.

I can easily do this with a macro that would fill down the formula in B1 to the last row of data, but I do not want the user to have to run a macro every time they start a new line.

Is there a way to kick off a macro by virtue that the A2 cell changed or lost focus--user hit enter or moused to another cell, etc.

Thanks.



Answer this question

If a cell has value add a formula to neighbouring cell

  • ManishMenon

    here is someVBA pseudo code that will get ya going down the right path

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells = Range("A2") Then
    If Target.Value <> 0 Then
    Target.Offset(0, 1).Formula = ("=A2 +1")
    End If

    End If
    End Sub



  • If a cell has value add a formula to neighbouring cell