Excel VBA - VBA script does not work on target sheet once I copy a value from another sheet











up vote
0
down vote

favorite












I use the following VBA script:



    Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xCount As Long
Dim valueCell As Range
Dim timeStampCell As Range
Dim targetCell As Range
Dim xVal As Long

Application.EnableEvents = False

'''''EDIT''''''

Set targetCell = Range("G15")
Set timeStampCell = Range("R2")
Set valueCell = timeStampCell.Offset(0, 1)

'''''''''''''''

xCount = Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 1

If Target.Address = targetCell.Address Then
valueCell.Offset(xCount, 0).Value = targetCell.Value
timeStampCell.Offset(xCount, 0).Value = Date
Else
If valueCell.Offset(Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
valueCell.Offset(xCount, 0).Value = targetCell.Value
timeStampCell.Offset(xCount, 0).Value = Date
End If
End If

Application.EnableEvents = True

End Sub


It works properly when I use it in the active sheet (Data).
Actually, the script checks if there is a change in the target value (the value is updated using formulas from other cells) and if the target value (G15) has been changed, then copy the new value in the first available row of the table.



The problem is that I need to move the table to another sheet.
I used a formula which copies the value from G15 of the initial sheet to the cell E1 of the new sheet (MonthlyData) and I moved the VBA script from "Data" to "MonthlyData". I have modified the script as follows:



Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xCount As Long
Dim valueCell As Range
Dim timeStampCell As Range
Dim targetCell As Range
Dim xVal As Long

Application.EnableEvents = False

'''''EDIT''''''

Set targetCell = Sheets("MonthlyData").Range("E1")
Set timeStampCell = Sheets("MonthlyData").Range("A2")
Set valueCell = timeStampCell.Offset(0, 1)

'''''''''''''''

xCount = Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 1

If Target.Address = targetCell.Address Then
valueCell.Offset(xCount, 0).Value = targetCell.Value
timeStampCell.Offset(xCount, 0).Value = Date
Else
If valueCell.Offset(Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
valueCell.Offset(xCount, 0).Value = targetCell.Value
timeStampCell.Offset(xCount, 0).Value = Date
End If
End If
Application.EnableEvents = True

End Sub


And now the problem... If I manually update the E1 cell to another value works perfect, if the value E1 change automatically changing a value from sheet (Data) the value E1 in MonthlyData being updated but the VBA script does not work and the value is not updated in the table...



Can anyone help?



Thanks










share|improve this question


























    up vote
    0
    down vote

    favorite












    I use the following VBA script:



        Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xCount As Long
    Dim valueCell As Range
    Dim timeStampCell As Range
    Dim targetCell As Range
    Dim xVal As Long

    Application.EnableEvents = False

    '''''EDIT''''''

    Set targetCell = Range("G15")
    Set timeStampCell = Range("R2")
    Set valueCell = timeStampCell.Offset(0, 1)

    '''''''''''''''

    xCount = Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 1

    If Target.Address = targetCell.Address Then
    valueCell.Offset(xCount, 0).Value = targetCell.Value
    timeStampCell.Offset(xCount, 0).Value = Date
    Else
    If valueCell.Offset(Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
    valueCell.Offset(xCount, 0).Value = targetCell.Value
    timeStampCell.Offset(xCount, 0).Value = Date
    End If
    End If

    Application.EnableEvents = True

    End Sub


    It works properly when I use it in the active sheet (Data).
    Actually, the script checks if there is a change in the target value (the value is updated using formulas from other cells) and if the target value (G15) has been changed, then copy the new value in the first available row of the table.



    The problem is that I need to move the table to another sheet.
    I used a formula which copies the value from G15 of the initial sheet to the cell E1 of the new sheet (MonthlyData) and I moved the VBA script from "Data" to "MonthlyData". I have modified the script as follows:



    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xCount As Long
    Dim valueCell As Range
    Dim timeStampCell As Range
    Dim targetCell As Range
    Dim xVal As Long

    Application.EnableEvents = False

    '''''EDIT''''''

    Set targetCell = Sheets("MonthlyData").Range("E1")
    Set timeStampCell = Sheets("MonthlyData").Range("A2")
    Set valueCell = timeStampCell.Offset(0, 1)

    '''''''''''''''

    xCount = Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 1

    If Target.Address = targetCell.Address Then
    valueCell.Offset(xCount, 0).Value = targetCell.Value
    timeStampCell.Offset(xCount, 0).Value = Date
    Else
    If valueCell.Offset(Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
    valueCell.Offset(xCount, 0).Value = targetCell.Value
    timeStampCell.Offset(xCount, 0).Value = Date
    End If
    End If
    Application.EnableEvents = True

    End Sub


    And now the problem... If I manually update the E1 cell to another value works perfect, if the value E1 change automatically changing a value from sheet (Data) the value E1 in MonthlyData being updated but the VBA script does not work and the value is not updated in the table...



    Can anyone help?



    Thanks










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I use the following VBA script:



          Option Explicit

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xCount As Long
      Dim valueCell As Range
      Dim timeStampCell As Range
      Dim targetCell As Range
      Dim xVal As Long

      Application.EnableEvents = False

      '''''EDIT''''''

      Set targetCell = Range("G15")
      Set timeStampCell = Range("R2")
      Set valueCell = timeStampCell.Offset(0, 1)

      '''''''''''''''

      xCount = Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 1

      If Target.Address = targetCell.Address Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      Else
      If valueCell.Offset(Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      End If
      End If

      Application.EnableEvents = True

      End Sub


      It works properly when I use it in the active sheet (Data).
      Actually, the script checks if there is a change in the target value (the value is updated using formulas from other cells) and if the target value (G15) has been changed, then copy the new value in the first available row of the table.



      The problem is that I need to move the table to another sheet.
      I used a formula which copies the value from G15 of the initial sheet to the cell E1 of the new sheet (MonthlyData) and I moved the VBA script from "Data" to "MonthlyData". I have modified the script as follows:



      Option Explicit
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xCount As Long
      Dim valueCell As Range
      Dim timeStampCell As Range
      Dim targetCell As Range
      Dim xVal As Long

      Application.EnableEvents = False

      '''''EDIT''''''

      Set targetCell = Sheets("MonthlyData").Range("E1")
      Set timeStampCell = Sheets("MonthlyData").Range("A2")
      Set valueCell = timeStampCell.Offset(0, 1)

      '''''''''''''''

      xCount = Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 1

      If Target.Address = targetCell.Address Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      Else
      If valueCell.Offset(Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      End If
      End If
      Application.EnableEvents = True

      End Sub


      And now the problem... If I manually update the E1 cell to another value works perfect, if the value E1 change automatically changing a value from sheet (Data) the value E1 in MonthlyData being updated but the VBA script does not work and the value is not updated in the table...



      Can anyone help?



      Thanks










      share|improve this question













      I use the following VBA script:



          Option Explicit

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xCount As Long
      Dim valueCell As Range
      Dim timeStampCell As Range
      Dim targetCell As Range
      Dim xVal As Long

      Application.EnableEvents = False

      '''''EDIT''''''

      Set targetCell = Range("G15")
      Set timeStampCell = Range("R2")
      Set valueCell = timeStampCell.Offset(0, 1)

      '''''''''''''''

      xCount = Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 1

      If Target.Address = targetCell.Address Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      Else
      If valueCell.Offset(Cells(ActiveSheet.Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      End If
      End If

      Application.EnableEvents = True

      End Sub


      It works properly when I use it in the active sheet (Data).
      Actually, the script checks if there is a change in the target value (the value is updated using formulas from other cells) and if the target value (G15) has been changed, then copy the new value in the first available row of the table.



      The problem is that I need to move the table to another sheet.
      I used a formula which copies the value from G15 of the initial sheet to the cell E1 of the new sheet (MonthlyData) and I moved the VBA script from "Data" to "MonthlyData". I have modified the script as follows:



      Option Explicit
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xCount As Long
      Dim valueCell As Range
      Dim timeStampCell As Range
      Dim targetCell As Range
      Dim xVal As Long

      Application.EnableEvents = False

      '''''EDIT''''''

      Set targetCell = Sheets("MonthlyData").Range("E1")
      Set timeStampCell = Sheets("MonthlyData").Range("A2")
      Set valueCell = timeStampCell.Offset(0, 1)

      '''''''''''''''

      xCount = Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 1

      If Target.Address = targetCell.Address Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      Else
      If valueCell.Offset(Cells(Sheets("MonthlyData").Rows.Count, valueCell.Column).End(xlUp).Row - 2, 0).Value <> targetCell.Value Then
      valueCell.Offset(xCount, 0).Value = targetCell.Value
      timeStampCell.Offset(xCount, 0).Value = Date
      End If
      End If
      Application.EnableEvents = True

      End Sub


      And now the problem... If I manually update the E1 cell to another value works perfect, if the value E1 change automatically changing a value from sheet (Data) the value E1 in MonthlyData being updated but the VBA script does not work and the value is not updated in the table...



      Can anyone help?



      Thanks







      excel vba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 9:58









      Wolf

      487




      487
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          I think you need to add code Worksheet_Change event on Data sheet as well. I am using this as an example if Sheets("MonthlyData").Range("E1") is a formula that came from Sheets("Data").Range("A1")
          Please add this code to Data sheet:



          Option Explicit
          Private Sub Worksheet_Change(ByVal Target As Range)

          If Target.Range("A1") Then
          Sheets("MonthlyData").Range("E1").Formula = Sheets("MonthlyData").Range("E1").Formula
          End If

          End Sub


          Hope this help.



          Thanks.






          share|improve this answer




























            up vote
            0
            down vote













            Worksheet_Change event in MonthlyData sheet supposed not to fire as there is no change in that sheet. Only value of the cell is being changed.



            It is better to wrap up the code for Worksheet_Changeof "MonthlyData" in a sub procedure and call it from DATA sheet's Worksheet_Change event from within the if branch where G10 is found changed.



            Or



            Simply change MonthlyData Sheet's E1 Cell directly from with in Worksheet_Change event of DATA sheet by adding one line



            Sheets("MonthlyData").Range("E1").Value= targetCell.Value


            EDIT:I tried the firing of Sheet("MonthlyData") Worksheet_Change event with the following code placed in Sheet("DATA") Worksheet_Change event.



            Private Sub Worksheet_Change(ByVal Target As Range)
            If Target = Sheets("DATA").Range("G10") Then
            Sheets("MonthlyData").Range("E1").Value = Sheets("DATA").Range("G10").Value
            End If
            End Sub


            It is successfully putting G10 (I used G10 instead of G15) value to E1 and firing of Sheet("MonthlyData") Worksheet_Change event. it is again checked with your full code of MonthlyData Worksheet_Change event and found working.



            ScreenShot






            share|improve this answer























            • Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
              – Wolf
              Nov 11 at 14:48










            • Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
              – Wolf
              Nov 11 at 19:29










            • In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
              – Ahmed AU
              Nov 12 at 1:18













            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247583%2fexcel-vba-vba-script-does-not-work-on-target-sheet-once-i-copy-a-value-from-an%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I think you need to add code Worksheet_Change event on Data sheet as well. I am using this as an example if Sheets("MonthlyData").Range("E1") is a formula that came from Sheets("Data").Range("A1")
            Please add this code to Data sheet:



            Option Explicit
            Private Sub Worksheet_Change(ByVal Target As Range)

            If Target.Range("A1") Then
            Sheets("MonthlyData").Range("E1").Formula = Sheets("MonthlyData").Range("E1").Formula
            End If

            End Sub


            Hope this help.



            Thanks.






            share|improve this answer

























              up vote
              0
              down vote













              I think you need to add code Worksheet_Change event on Data sheet as well. I am using this as an example if Sheets("MonthlyData").Range("E1") is a formula that came from Sheets("Data").Range("A1")
              Please add this code to Data sheet:



              Option Explicit
              Private Sub Worksheet_Change(ByVal Target As Range)

              If Target.Range("A1") Then
              Sheets("MonthlyData").Range("E1").Formula = Sheets("MonthlyData").Range("E1").Formula
              End If

              End Sub


              Hope this help.



              Thanks.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I think you need to add code Worksheet_Change event on Data sheet as well. I am using this as an example if Sheets("MonthlyData").Range("E1") is a formula that came from Sheets("Data").Range("A1")
                Please add this code to Data sheet:



                Option Explicit
                Private Sub Worksheet_Change(ByVal Target As Range)

                If Target.Range("A1") Then
                Sheets("MonthlyData").Range("E1").Formula = Sheets("MonthlyData").Range("E1").Formula
                End If

                End Sub


                Hope this help.



                Thanks.






                share|improve this answer












                I think you need to add code Worksheet_Change event on Data sheet as well. I am using this as an example if Sheets("MonthlyData").Range("E1") is a formula that came from Sheets("Data").Range("A1")
                Please add this code to Data sheet:



                Option Explicit
                Private Sub Worksheet_Change(ByVal Target As Range)

                If Target.Range("A1") Then
                Sheets("MonthlyData").Range("E1").Formula = Sheets("MonthlyData").Range("E1").Formula
                End If

                End Sub


                Hope this help.



                Thanks.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 18:08









                adhy wijaya

                43817




                43817
























                    up vote
                    0
                    down vote













                    Worksheet_Change event in MonthlyData sheet supposed not to fire as there is no change in that sheet. Only value of the cell is being changed.



                    It is better to wrap up the code for Worksheet_Changeof "MonthlyData" in a sub procedure and call it from DATA sheet's Worksheet_Change event from within the if branch where G10 is found changed.



                    Or



                    Simply change MonthlyData Sheet's E1 Cell directly from with in Worksheet_Change event of DATA sheet by adding one line



                    Sheets("MonthlyData").Range("E1").Value= targetCell.Value


                    EDIT:I tried the firing of Sheet("MonthlyData") Worksheet_Change event with the following code placed in Sheet("DATA") Worksheet_Change event.



                    Private Sub Worksheet_Change(ByVal Target As Range)
                    If Target = Sheets("DATA").Range("G10") Then
                    Sheets("MonthlyData").Range("E1").Value = Sheets("DATA").Range("G10").Value
                    End If
                    End Sub


                    It is successfully putting G10 (I used G10 instead of G15) value to E1 and firing of Sheet("MonthlyData") Worksheet_Change event. it is again checked with your full code of MonthlyData Worksheet_Change event and found working.



                    ScreenShot






                    share|improve this answer























                    • Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
                      – Wolf
                      Nov 11 at 14:48










                    • Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
                      – Wolf
                      Nov 11 at 19:29










                    • In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
                      – Ahmed AU
                      Nov 12 at 1:18

















                    up vote
                    0
                    down vote













                    Worksheet_Change event in MonthlyData sheet supposed not to fire as there is no change in that sheet. Only value of the cell is being changed.



                    It is better to wrap up the code for Worksheet_Changeof "MonthlyData" in a sub procedure and call it from DATA sheet's Worksheet_Change event from within the if branch where G10 is found changed.



                    Or



                    Simply change MonthlyData Sheet's E1 Cell directly from with in Worksheet_Change event of DATA sheet by adding one line



                    Sheets("MonthlyData").Range("E1").Value= targetCell.Value


                    EDIT:I tried the firing of Sheet("MonthlyData") Worksheet_Change event with the following code placed in Sheet("DATA") Worksheet_Change event.



                    Private Sub Worksheet_Change(ByVal Target As Range)
                    If Target = Sheets("DATA").Range("G10") Then
                    Sheets("MonthlyData").Range("E1").Value = Sheets("DATA").Range("G10").Value
                    End If
                    End Sub


                    It is successfully putting G10 (I used G10 instead of G15) value to E1 and firing of Sheet("MonthlyData") Worksheet_Change event. it is again checked with your full code of MonthlyData Worksheet_Change event and found working.



                    ScreenShot






                    share|improve this answer























                    • Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
                      – Wolf
                      Nov 11 at 14:48










                    • Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
                      – Wolf
                      Nov 11 at 19:29










                    • In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
                      – Ahmed AU
                      Nov 12 at 1:18















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Worksheet_Change event in MonthlyData sheet supposed not to fire as there is no change in that sheet. Only value of the cell is being changed.



                    It is better to wrap up the code for Worksheet_Changeof "MonthlyData" in a sub procedure and call it from DATA sheet's Worksheet_Change event from within the if branch where G10 is found changed.



                    Or



                    Simply change MonthlyData Sheet's E1 Cell directly from with in Worksheet_Change event of DATA sheet by adding one line



                    Sheets("MonthlyData").Range("E1").Value= targetCell.Value


                    EDIT:I tried the firing of Sheet("MonthlyData") Worksheet_Change event with the following code placed in Sheet("DATA") Worksheet_Change event.



                    Private Sub Worksheet_Change(ByVal Target As Range)
                    If Target = Sheets("DATA").Range("G10") Then
                    Sheets("MonthlyData").Range("E1").Value = Sheets("DATA").Range("G10").Value
                    End If
                    End Sub


                    It is successfully putting G10 (I used G10 instead of G15) value to E1 and firing of Sheet("MonthlyData") Worksheet_Change event. it is again checked with your full code of MonthlyData Worksheet_Change event and found working.



                    ScreenShot






                    share|improve this answer














                    Worksheet_Change event in MonthlyData sheet supposed not to fire as there is no change in that sheet. Only value of the cell is being changed.



                    It is better to wrap up the code for Worksheet_Changeof "MonthlyData" in a sub procedure and call it from DATA sheet's Worksheet_Change event from within the if branch where G10 is found changed.



                    Or



                    Simply change MonthlyData Sheet's E1 Cell directly from with in Worksheet_Change event of DATA sheet by adding one line



                    Sheets("MonthlyData").Range("E1").Value= targetCell.Value


                    EDIT:I tried the firing of Sheet("MonthlyData") Worksheet_Change event with the following code placed in Sheet("DATA") Worksheet_Change event.



                    Private Sub Worksheet_Change(ByVal Target As Range)
                    If Target = Sheets("DATA").Range("G10") Then
                    Sheets("MonthlyData").Range("E1").Value = Sheets("DATA").Range("G10").Value
                    End If
                    End Sub


                    It is successfully putting G10 (I used G10 instead of G15) value to E1 and firing of Sheet("MonthlyData") Worksheet_Change event. it is again checked with your full code of MonthlyData Worksheet_Change event and found working.



                    ScreenShot







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 12 at 1:42

























                    answered Nov 11 at 10:40









                    Ahmed AU

                    60028




                    60028












                    • Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
                      – Wolf
                      Nov 11 at 14:48










                    • Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
                      – Wolf
                      Nov 11 at 19:29










                    • In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
                      – Ahmed AU
                      Nov 12 at 1:18




















                    • Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
                      – Wolf
                      Nov 11 at 14:48










                    • Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
                      – Wolf
                      Nov 11 at 19:29










                    • In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
                      – Ahmed AU
                      Nov 12 at 1:18


















                    Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
                    – Wolf
                    Nov 11 at 14:48




                    Hi Ahmed, thank you for help. I didn't manage to fix it with your suggestion... Can you please give me the second option that you have suggested as part of the script? I mean if you have tried and it worked if possible add here all the script with your correction...
                    – Wolf
                    Nov 11 at 14:48












                    Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
                    – Wolf
                    Nov 11 at 19:29




                    Hi Ahmed, I have tried before this but it didn't solve my problem, the second sheet behaves with exactly same way as to use formula. With both ways, the value in E1 of the MonthlyData is updated but the VBA does not work in order to add a line at the end of the table. If I manually change the value in E1 does it...
                    – Wolf
                    Nov 11 at 19:29












                    In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
                    – Ahmed AU
                    Nov 12 at 1:18






                    In your question you told 'I moved the VBA script from "Data" to "MonthlyData".. If you are still using using your full Worksheet_Change event in DATA. then just delete Application.EnableEvents = False. It may be preventing MonthlyData Change event from firing. Waiting for your feedback..
                    – Ahmed AU
                    Nov 12 at 1:18




















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247583%2fexcel-vba-vba-script-does-not-work-on-target-sheet-once-i-copy-a-value-from-an%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python