Forum Discussion

kobus1305's avatar
kobus1305
Brass Contributor
Nov 02, 2020
Solved

Keep a Value

I may be this is a stupid question but i am sitting and thinking is it all possible. We all know how if statement works. Logical test, if test is true, if test is false!! Is it possible that, if test...
  • NikolinoDE's avatar
    Nov 02, 2020

    kobus1305 

     

    Something like that, in that direction?

    If cell A2 contains the text "x"; then enter the value 9 in cell A1; otherwise "leave everything as it is"

    VBA code:

     

    Private Sub Worksheet_Change (ByVal Target As Range)
    If Target.Address = "$ A $ 2" Then
    If LCase (Range ("A2")) = "x" Then
    Application.EnableEvents = False
    Range ("A1") = 9
    Application.EnableEvents = True
    End If
    End If
    End Sub

     

     or in formula?

    =IF(A2="x",9,A1)

     

    Hope I was able to help you.

     

    Nikolino

    I know I don't know anything (Socrates)

     

    * Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here