Search code examples
vbaexcelreplacecell

Automatically replace cell value based on another cell - VBA


So, i´m new at this...

I have this code:

    Private Sub Worksheet_Change()


    If Range("C2").Value = "T0" Then
        Range("C4").Value = "1"
    End If


End Sub

But excel keeps on giving me a "Run-time error 28 : Out of stack space"


Solution

  • Private Sub Worksheet_Change(ByVal Target As Range) If target.address="$C$2" and target.value = "T0" Then Range("C4").Value = "1" End If End Sub

    Checking the target address being C2 is optional, I was assuming that C2 is changed which is what you are trapping.