How to insert rows value automatically based on another cell value












0















At first, please look this excel worksheet:
enter image description here



The month table contains whole year data. If I select any month from the table by typing or by selecting from drop down menu (e.g "Selected") then only those rows will be appeared after certain rows. As for example I want that the selected rows will be appeared after rows 14 and onward (i.e Rows will not be appeared before row 15). How to achieve this?



For your kind information, Number of selected rows may vary. As for example, in the above table there are two rows selected (April & September). But it might be March, April & September selected. So I can't specify a cell range in which the selected rows will be appeared. Also, there will be some text on Rows 17. So, the selected rows have to inserted dynamically after rows 14.



Any idea how to achieve this?










share|improve this question























  • It could technically be done with a macro as well. Do you want the "appeared" rows to be in order of month, or in order of selection?

    – Christofer Weber
    Nov 27 '16 at 12:37











  • In order of selection

    – Abdullah Mamun-Ur- Rashid
    Nov 28 '16 at 7:48
















0















At first, please look this excel worksheet:
enter image description here



The month table contains whole year data. If I select any month from the table by typing or by selecting from drop down menu (e.g "Selected") then only those rows will be appeared after certain rows. As for example I want that the selected rows will be appeared after rows 14 and onward (i.e Rows will not be appeared before row 15). How to achieve this?



For your kind information, Number of selected rows may vary. As for example, in the above table there are two rows selected (April & September). But it might be March, April & September selected. So I can't specify a cell range in which the selected rows will be appeared. Also, there will be some text on Rows 17. So, the selected rows have to inserted dynamically after rows 14.



Any idea how to achieve this?










share|improve this question























  • It could technically be done with a macro as well. Do you want the "appeared" rows to be in order of month, or in order of selection?

    – Christofer Weber
    Nov 27 '16 at 12:37











  • In order of selection

    – Abdullah Mamun-Ur- Rashid
    Nov 28 '16 at 7:48














0












0








0








At first, please look this excel worksheet:
enter image description here



The month table contains whole year data. If I select any month from the table by typing or by selecting from drop down menu (e.g "Selected") then only those rows will be appeared after certain rows. As for example I want that the selected rows will be appeared after rows 14 and onward (i.e Rows will not be appeared before row 15). How to achieve this?



For your kind information, Number of selected rows may vary. As for example, in the above table there are two rows selected (April & September). But it might be March, April & September selected. So I can't specify a cell range in which the selected rows will be appeared. Also, there will be some text on Rows 17. So, the selected rows have to inserted dynamically after rows 14.



Any idea how to achieve this?










share|improve this question














At first, please look this excel worksheet:
enter image description here



The month table contains whole year data. If I select any month from the table by typing or by selecting from drop down menu (e.g "Selected") then only those rows will be appeared after certain rows. As for example I want that the selected rows will be appeared after rows 14 and onward (i.e Rows will not be appeared before row 15). How to achieve this?



For your kind information, Number of selected rows may vary. As for example, in the above table there are two rows selected (April & September). But it might be March, April & September selected. So I can't specify a cell range in which the selected rows will be appeared. Also, there will be some text on Rows 17. So, the selected rows have to inserted dynamically after rows 14.



Any idea how to achieve this?







microsoft-excel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '16 at 7:50









Abdullah Mamun-Ur- RashidAbdullah Mamun-Ur- Rashid

12527




12527













  • It could technically be done with a macro as well. Do you want the "appeared" rows to be in order of month, or in order of selection?

    – Christofer Weber
    Nov 27 '16 at 12:37











  • In order of selection

    – Abdullah Mamun-Ur- Rashid
    Nov 28 '16 at 7:48



















  • It could technically be done with a macro as well. Do you want the "appeared" rows to be in order of month, or in order of selection?

    – Christofer Weber
    Nov 27 '16 at 12:37











  • In order of selection

    – Abdullah Mamun-Ur- Rashid
    Nov 28 '16 at 7:48

















It could technically be done with a macro as well. Do you want the "appeared" rows to be in order of month, or in order of selection?

– Christofer Weber
Nov 27 '16 at 12:37





It could technically be done with a macro as well. Do you want the "appeared" rows to be in order of month, or in order of selection?

– Christofer Weber
Nov 27 '16 at 12:37













In order of selection

– Abdullah Mamun-Ur- Rashid
Nov 28 '16 at 7:48





In order of selection

– Abdullah Mamun-Ur- Rashid
Nov 28 '16 at 7:48










2 Answers
2






active

oldest

votes


















0














I would probably go using a PivotTable. Month would go in COLUMNS while B, C & D in VALUES (this should essentially make the table look more or less the same as yours). The selection parametre then needs to be put into FILTERS to show only the stuff you want.



The bad thing about is that each team you want changes to be displayed, you need refresh the PivotTable (RMB and Refresh or through Analyse; alternatively you can use a macro to do it periodically for you).






share|improve this answer































    0














    Step 1 - The list



    First you can add the "Selected" part with a drop down list.

    With E1 selected, go to the Data tab and select Data Validation. Select List and write Selected as Source.

    Now drag E1 down to E12 to get the list on all the cells.



    Step 2 - The Code



    Adding rows

    To keep track of these cells changing a Worksheet_Change Sub works great.
    Right click your "Sheet1" (or equivalent) and select Show code.



    To track and copy the selected rows, we can do something like this:



    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer, r As Integer
    On Error GoTo EndM
    If Target.Value = "Selected" And Target.Column = 5 And Target.Row < 13 Then
    For r = 15 To 30
    If Cells(r, 1).Value = "" Then
    Range("A" & r & ":D" & r).Cells.Value = Range("A" & Target.Row & ":D" & Target.Row).Cells.Value
    i = 1
    End If
    If i > 0 Then GoTo EndM
    Next r
    End If
    EndM:
    End Sub


    This looks for changes in the sheet. And if the change any cell from E1 to E12 being changed to "select", then it copies the columns A to D of the same row, into the first empty row starting from row 15.
    Note
    This does not stop you from selecting the same entry twice, i.e. getting two rows of January. It's also set to a limit of row 30. After row 30 it will not add more entries Can be changed by changing the value 30 in For r = 15 To 30



    Deleting rows

    We can use basically the same method to delete the rows again when we delete the "Selected" value by adding



    If Target.Column = 5 And Target.Row < 13 And Target.Value = "" Then
    For r = 15 To 30
    If Cells(r, 1).Value = Cells(Target.Row, 1) Then
    Range("A" & r & ":D" & r).Cells.Delete
    End If
    Next r
    End If


    Between End If and EndM: in previous example.



    The Error handler is needed for the sheet not to throw an error at you every time you try to delete multiple cells at a time.
    Note
    This will not run if you delete multiple cells at one time, and will not delete every row if the same month is present twice in a row.



    You can of course add or change functionality, like restricting the addition of multiple entries by adding:



                ElseIf Cells(r, 1).Value = Cells(.Row, 1).Value Then
    MsgBox ("Multiple entries are not allowed!")
    GoTo EndM


    Between i = 1 and End If in the Adding part.

    Good luck!






    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      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',
      autoActivateHeartbeat: false,
      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%2fsuperuser.com%2fquestions%2f1150168%2fhow-to-insert-rows-value-automatically-based-on-another-cell-value%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









      0














      I would probably go using a PivotTable. Month would go in COLUMNS while B, C & D in VALUES (this should essentially make the table look more or less the same as yours). The selection parametre then needs to be put into FILTERS to show only the stuff you want.



      The bad thing about is that each team you want changes to be displayed, you need refresh the PivotTable (RMB and Refresh or through Analyse; alternatively you can use a macro to do it periodically for you).






      share|improve this answer




























        0














        I would probably go using a PivotTable. Month would go in COLUMNS while B, C & D in VALUES (this should essentially make the table look more or less the same as yours). The selection parametre then needs to be put into FILTERS to show only the stuff you want.



        The bad thing about is that each team you want changes to be displayed, you need refresh the PivotTable (RMB and Refresh or through Analyse; alternatively you can use a macro to do it periodically for you).






        share|improve this answer


























          0












          0








          0







          I would probably go using a PivotTable. Month would go in COLUMNS while B, C & D in VALUES (this should essentially make the table look more or less the same as yours). The selection parametre then needs to be put into FILTERS to show only the stuff you want.



          The bad thing about is that each team you want changes to be displayed, you need refresh the PivotTable (RMB and Refresh or through Analyse; alternatively you can use a macro to do it periodically for you).






          share|improve this answer













          I would probably go using a PivotTable. Month would go in COLUMNS while B, C & D in VALUES (this should essentially make the table look more or less the same as yours). The selection parametre then needs to be put into FILTERS to show only the stuff you want.



          The bad thing about is that each team you want changes to be displayed, you need refresh the PivotTable (RMB and Refresh or through Analyse; alternatively you can use a macro to do it periodically for you).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '16 at 11:29









          ElesharEleshar

          1




          1

























              0














              Step 1 - The list



              First you can add the "Selected" part with a drop down list.

              With E1 selected, go to the Data tab and select Data Validation. Select List and write Selected as Source.

              Now drag E1 down to E12 to get the list on all the cells.



              Step 2 - The Code



              Adding rows

              To keep track of these cells changing a Worksheet_Change Sub works great.
              Right click your "Sheet1" (or equivalent) and select Show code.



              To track and copy the selected rows, we can do something like this:



              Private Sub Worksheet_Change(ByVal Target As Range)
              Dim i As Integer, r As Integer
              On Error GoTo EndM
              If Target.Value = "Selected" And Target.Column = 5 And Target.Row < 13 Then
              For r = 15 To 30
              If Cells(r, 1).Value = "" Then
              Range("A" & r & ":D" & r).Cells.Value = Range("A" & Target.Row & ":D" & Target.Row).Cells.Value
              i = 1
              End If
              If i > 0 Then GoTo EndM
              Next r
              End If
              EndM:
              End Sub


              This looks for changes in the sheet. And if the change any cell from E1 to E12 being changed to "select", then it copies the columns A to D of the same row, into the first empty row starting from row 15.
              Note
              This does not stop you from selecting the same entry twice, i.e. getting two rows of January. It's also set to a limit of row 30. After row 30 it will not add more entries Can be changed by changing the value 30 in For r = 15 To 30



              Deleting rows

              We can use basically the same method to delete the rows again when we delete the "Selected" value by adding



              If Target.Column = 5 And Target.Row < 13 And Target.Value = "" Then
              For r = 15 To 30
              If Cells(r, 1).Value = Cells(Target.Row, 1) Then
              Range("A" & r & ":D" & r).Cells.Delete
              End If
              Next r
              End If


              Between End If and EndM: in previous example.



              The Error handler is needed for the sheet not to throw an error at you every time you try to delete multiple cells at a time.
              Note
              This will not run if you delete multiple cells at one time, and will not delete every row if the same month is present twice in a row.



              You can of course add or change functionality, like restricting the addition of multiple entries by adding:



                          ElseIf Cells(r, 1).Value = Cells(.Row, 1).Value Then
              MsgBox ("Multiple entries are not allowed!")
              GoTo EndM


              Between i = 1 and End If in the Adding part.

              Good luck!






              share|improve this answer




























                0














                Step 1 - The list



                First you can add the "Selected" part with a drop down list.

                With E1 selected, go to the Data tab and select Data Validation. Select List and write Selected as Source.

                Now drag E1 down to E12 to get the list on all the cells.



                Step 2 - The Code



                Adding rows

                To keep track of these cells changing a Worksheet_Change Sub works great.
                Right click your "Sheet1" (or equivalent) and select Show code.



                To track and copy the selected rows, we can do something like this:



                Private Sub Worksheet_Change(ByVal Target As Range)
                Dim i As Integer, r As Integer
                On Error GoTo EndM
                If Target.Value = "Selected" And Target.Column = 5 And Target.Row < 13 Then
                For r = 15 To 30
                If Cells(r, 1).Value = "" Then
                Range("A" & r & ":D" & r).Cells.Value = Range("A" & Target.Row & ":D" & Target.Row).Cells.Value
                i = 1
                End If
                If i > 0 Then GoTo EndM
                Next r
                End If
                EndM:
                End Sub


                This looks for changes in the sheet. And if the change any cell from E1 to E12 being changed to "select", then it copies the columns A to D of the same row, into the first empty row starting from row 15.
                Note
                This does not stop you from selecting the same entry twice, i.e. getting two rows of January. It's also set to a limit of row 30. After row 30 it will not add more entries Can be changed by changing the value 30 in For r = 15 To 30



                Deleting rows

                We can use basically the same method to delete the rows again when we delete the "Selected" value by adding



                If Target.Column = 5 And Target.Row < 13 And Target.Value = "" Then
                For r = 15 To 30
                If Cells(r, 1).Value = Cells(Target.Row, 1) Then
                Range("A" & r & ":D" & r).Cells.Delete
                End If
                Next r
                End If


                Between End If and EndM: in previous example.



                The Error handler is needed for the sheet not to throw an error at you every time you try to delete multiple cells at a time.
                Note
                This will not run if you delete multiple cells at one time, and will not delete every row if the same month is present twice in a row.



                You can of course add or change functionality, like restricting the addition of multiple entries by adding:



                            ElseIf Cells(r, 1).Value = Cells(.Row, 1).Value Then
                MsgBox ("Multiple entries are not allowed!")
                GoTo EndM


                Between i = 1 and End If in the Adding part.

                Good luck!






                share|improve this answer


























                  0












                  0








                  0







                  Step 1 - The list



                  First you can add the "Selected" part with a drop down list.

                  With E1 selected, go to the Data tab and select Data Validation. Select List and write Selected as Source.

                  Now drag E1 down to E12 to get the list on all the cells.



                  Step 2 - The Code



                  Adding rows

                  To keep track of these cells changing a Worksheet_Change Sub works great.
                  Right click your "Sheet1" (or equivalent) and select Show code.



                  To track and copy the selected rows, we can do something like this:



                  Private Sub Worksheet_Change(ByVal Target As Range)
                  Dim i As Integer, r As Integer
                  On Error GoTo EndM
                  If Target.Value = "Selected" And Target.Column = 5 And Target.Row < 13 Then
                  For r = 15 To 30
                  If Cells(r, 1).Value = "" Then
                  Range("A" & r & ":D" & r).Cells.Value = Range("A" & Target.Row & ":D" & Target.Row).Cells.Value
                  i = 1
                  End If
                  If i > 0 Then GoTo EndM
                  Next r
                  End If
                  EndM:
                  End Sub


                  This looks for changes in the sheet. And if the change any cell from E1 to E12 being changed to "select", then it copies the columns A to D of the same row, into the first empty row starting from row 15.
                  Note
                  This does not stop you from selecting the same entry twice, i.e. getting two rows of January. It's also set to a limit of row 30. After row 30 it will not add more entries Can be changed by changing the value 30 in For r = 15 To 30



                  Deleting rows

                  We can use basically the same method to delete the rows again when we delete the "Selected" value by adding



                  If Target.Column = 5 And Target.Row < 13 And Target.Value = "" Then
                  For r = 15 To 30
                  If Cells(r, 1).Value = Cells(Target.Row, 1) Then
                  Range("A" & r & ":D" & r).Cells.Delete
                  End If
                  Next r
                  End If


                  Between End If and EndM: in previous example.



                  The Error handler is needed for the sheet not to throw an error at you every time you try to delete multiple cells at a time.
                  Note
                  This will not run if you delete multiple cells at one time, and will not delete every row if the same month is present twice in a row.



                  You can of course add or change functionality, like restricting the addition of multiple entries by adding:



                              ElseIf Cells(r, 1).Value = Cells(.Row, 1).Value Then
                  MsgBox ("Multiple entries are not allowed!")
                  GoTo EndM


                  Between i = 1 and End If in the Adding part.

                  Good luck!






                  share|improve this answer













                  Step 1 - The list



                  First you can add the "Selected" part with a drop down list.

                  With E1 selected, go to the Data tab and select Data Validation. Select List and write Selected as Source.

                  Now drag E1 down to E12 to get the list on all the cells.



                  Step 2 - The Code



                  Adding rows

                  To keep track of these cells changing a Worksheet_Change Sub works great.
                  Right click your "Sheet1" (or equivalent) and select Show code.



                  To track and copy the selected rows, we can do something like this:



                  Private Sub Worksheet_Change(ByVal Target As Range)
                  Dim i As Integer, r As Integer
                  On Error GoTo EndM
                  If Target.Value = "Selected" And Target.Column = 5 And Target.Row < 13 Then
                  For r = 15 To 30
                  If Cells(r, 1).Value = "" Then
                  Range("A" & r & ":D" & r).Cells.Value = Range("A" & Target.Row & ":D" & Target.Row).Cells.Value
                  i = 1
                  End If
                  If i > 0 Then GoTo EndM
                  Next r
                  End If
                  EndM:
                  End Sub


                  This looks for changes in the sheet. And if the change any cell from E1 to E12 being changed to "select", then it copies the columns A to D of the same row, into the first empty row starting from row 15.
                  Note
                  This does not stop you from selecting the same entry twice, i.e. getting two rows of January. It's also set to a limit of row 30. After row 30 it will not add more entries Can be changed by changing the value 30 in For r = 15 To 30



                  Deleting rows

                  We can use basically the same method to delete the rows again when we delete the "Selected" value by adding



                  If Target.Column = 5 And Target.Row < 13 And Target.Value = "" Then
                  For r = 15 To 30
                  If Cells(r, 1).Value = Cells(Target.Row, 1) Then
                  Range("A" & r & ":D" & r).Cells.Delete
                  End If
                  Next r
                  End If


                  Between End If and EndM: in previous example.



                  The Error handler is needed for the sheet not to throw an error at you every time you try to delete multiple cells at a time.
                  Note
                  This will not run if you delete multiple cells at one time, and will not delete every row if the same month is present twice in a row.



                  You can of course add or change functionality, like restricting the addition of multiple entries by adding:



                              ElseIf Cells(r, 1).Value = Cells(.Row, 1).Value Then
                  MsgBox ("Multiple entries are not allowed!")
                  GoTo EndM


                  Between i = 1 and End If in the Adding part.

                  Good luck!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 28 '16 at 12:08









                  Christofer WeberChristofer Weber

                  789413




                  789413






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • 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%2fsuperuser.com%2fquestions%2f1150168%2fhow-to-insert-rows-value-automatically-based-on-another-cell-value%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

                      Plaza Victoria

                      In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                      How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...