none
VBA when value in cell has changed RRS feed

  • Question

  • In one cell i people name

    in another i have there id

    i want to use VBA so when the name is changed insert vlookup in the

    and when the id is changed insert a different name

    so it always shows the person name and id

    would be even if vba just change the name id when other chnaged

    all i would like know for vba excel 2010 how run the code when cell value has changed 

    Tuesday, November 5, 2013 2:50 PM

Answers

  • Hi,

    You can run a macro when cells changes by using event (in the specific sheet add the event Worksheet_Change - Right click on the specific sheet and view code then add the code from the example below)

    For example if you want to run a macro when range("a1") changes:

        

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim TargetCells As Range

    Set TargetCells = Range("A1")

    If Not Application.Intersect(TargetCells, Range(Target.Address)) Is Nothing Then

    'Do something...

        MsgBox "Cells" & Target.Address & " was changed", vbInformation
    End If


    End Sub


    Guy Zommer

    • Marked as answer by philip_95 Thursday, November 7, 2013 1:20 PM
    Tuesday, November 5, 2013 7:56 PM

All replies

  • Hi,

    You can run a macro when cells changes by using event (in the specific sheet add the event Worksheet_Change - Right click on the specific sheet and view code then add the code from the example below)

    For example if you want to run a macro when range("a1") changes:

        

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim TargetCells As Range

    Set TargetCells = Range("A1")

    If Not Application.Intersect(TargetCells, Range(Target.Address)) Is Nothing Then

    'Do something...

        MsgBox "Cells" & Target.Address & " was changed", vbInformation
    End If


    End Sub


    Guy Zommer

    • Marked as answer by philip_95 Thursday, November 7, 2013 1:20 PM
    Tuesday, November 5, 2013 7:56 PM
  • thanks this will help
    Thursday, November 7, 2013 1:20 PM
  • You Welcome!

    Guy Zommer

    Thursday, November 7, 2013 1:21 PM