Moving Rows Based on Information in a Cell

%3CLINGO-SUB%20id%3D%22lingo-sub-1837649%22%20slang%3D%22en-US%22%3EMoving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1837649%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20create%20a%20Macro%20that%20when%20ran%20it%20will%20move%20certain%20rows%20depending%20on%20the%20value%20in%20the%20cells%20in%20a%20specific%20column.%20I%20have%20a%20spreadsheet%20that%20I%20need%20to%20split%20into%20two%20sheets%20depending%20upon%20the%20card%20numbers%20that%20are%20in%20one%20of%20the%20columns.%20Could%20someone%20help%20me%20with%20what%20the%20Macro%20for%20this%20would%20look%20like%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1837649%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1838522%22%20slang%3D%22de-DE%22%3ESubject%3A%20Moving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1838522%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F851948%22%20target%3D%22_blank%22%3E%40Brittany0724%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EHere%20is%20a%20small%3C%2FSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3Esolution%20approach%20with%20VBA%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%20%20%20Private%20Sub%20Worksheet_Change%20(ByVal%20Target%20As%20Range)%0A%20%20%20%20%20column%20%3D%20Target.Column%0A%20%20%20%20%20line%20%3D%20Target.Row%0A%20%20%20%20%20value%20%3D%20Target.Value%0A%20%20%20%20%20If%20column%20%3D%2011%20Then%0A%20%20%20%20%20%20%20%20%20Cells%20(line%2C%20value)%20.Value%20%3D%20Cells%20(line%2C%201)%0A%20%20%20%20%20End%20If%0A%20%20%20%20%20End%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20I%20was%20able%20to%20help%20you%20and%20would%20be%20happy%20to%20know%20if%20I%20could%20help%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1838559%22%20slang%3D%22en-US%22%3ERe%3A%20Moving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1838559%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F851948%22%20target%3D%22_blank%22%3E%40Brittany0724%3C%2FA%3E%26nbsp%3B%20alternatively%20you%20can%20leave%20the%20original%20sheet%20and%20on%20the%20other%202%20sheets%20just%20use%20the%20FILTER()%20function%20or%20a%20pivot%20table%20to%20populate%20that%20sheet%20with%20the%20corresponding%20data.%26nbsp%3B%20If%20you%20need%20help%20doing%20that%20you%20could%20supply%20a%20sample%20workbook%20(no%20personal%2Fconfidential%20info)%20and%20we%20could%20show%20you%20more%20specific%20answer(s).%20but%20in%20general%20a%20FILTER()%20would%20look%20like%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DFILTER(Sheet1!A%3AM%2CSheet1!A%3AA%3D%22only%20this%20id%22%2C%22None%20Found%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Ewhere%20%22only%20this%20id%22%20would%20be%20a%20number%20or%20text%20that%20should%20be%20matched%20for%20that%20row%20to%20be%20included%20and%20A%3AA%20be%20changed%20to%20the%20column%20of%20interest.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1858530%22%20slang%3D%22en-US%22%3EBetreff%3A%20Moving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1858530%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722750%22%20target%3D%22_blank%22%3E%40Nikolino%3C%2FA%3E%26nbsp%3BI%20think%20something%20like%20this%20is%20what%20I%20am%20looking%20for%20but%20maybe%20if%20I%20upload%20a%20sample%20file%20it%20will%20help%20some%20to%20narrow%20down%20what%20it%20would%20look%20like%20for%20me.%20I%20want%20to%20be%20able%20to%20run%20a%20macro%20that%20will%20split%20the%20list%20into%20two%20lists%20depending%20upon%20values%20in%20column%20B.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20a%20sample%20spreadsheet%20to%20help%20explain%20what%20I'm%20referring%20to.%20In%20the%20sample%2C%20values%20%22****00022%22%2C%20%22****00031%22%2C%20and%20%22****00141%22%20in%20column%20B%20would%20correspond%20with%20one%20list%20and%20values%20%22****00131%22%2C%20%22****00231%22%2C%20and%20%22****00201%22%20in%20column%20B%20would%20correspond%20with%20a%20second%20list.%20What%20is%20the%20best%20way%20to%20approach%20splitting%20the%20big%20list%20into%20two%20lists%20using%20VBA%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1860026%22%20slang%3D%22de-DE%22%3ESubject%3A%20Moving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1860026%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F851948%22%20target%3D%22_blank%22%3E%40Brittany0724%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3EPlease%20explain%20to%20me%20what%20exactly%20you%20would%20like%2C%20which%20data%20or%20content%20should%20be%20moved%20from%20which%20cell%20to%20which%3F%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3EEnclosed%20some%20information.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EHow%20to%20select%20cells%2Franges%20by%20using%20Visual%20Basic%20procedures%20in%20Excel%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Foffice%2Ftroubleshoot%2Foffice-developer%2Fselect-cells-rangs-with-visual-basic%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Foffice%2Ftroubleshoot%2Foffice-developer%2Fselect-cells-rangs-with-visual-basic%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3EExcuse%20me%20for%20the%20inconvenience%2C%20but%20need%20precise%20information%20in%20order%20to%20be%20able%20to%20provide%20you%20with%20an%20acceptable%20solution.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20understanding%20and%20patience%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1860886%22%20slang%3D%22en-US%22%3EBetreff%3A%20Moving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1860886%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722750%22%20target%3D%22_blank%22%3E%40Nikolino%3C%2FA%3E%26nbsp%3B%20No%20inconvenience%20at%20all.%20I%20appreciate%20your%20help.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20it%20to%20split%20the%20list%20into%20two%20depending%20on%20what%20information%20is%20in%20the%20%22Card%20number%22%20Column%20(B).%20I%20need%20the%20other%20two%20columns%20for%20that%20row%20to%20move%20with%20it%20as%20well.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20explain%20in%20more%20detail%2C%20if%20the%20%22card%20number%22%20(column%20B)%20is%20****00022%2C%20****00131%2C%20and%20****00231%20those%20cells%20and%20the%20cells%20in%20the%20same%20rows%20as%20those%20(the%20cells%20in%20column%20A%20%26amp%3B%20C)%20all%20need%20moved%20into%20a%20new%20sheet.%20The%20remaining%20%22card%20numbers%22%20and%20corresponding%20cells%20in%20the%20same%20rows%20can%20stay%20on%20the%20first%20sheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHopefully%20this%20makes%20more%20sense.%20If%20I%20need%20to%20clarify%20more%2C%20please%20let%20me%20know.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1862009%22%20slang%3D%22de-DE%22%3ESubject%3A%20Moving%20Rows%20Based%20on%20Information%20in%20a%20Cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1862009%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F851948%22%20target%3D%22_blank%22%3E%40Brittany0724%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3ESry%20but%20now%20I'm%20totally%20confused.%20Could%20you%20upload%20a%20file%20(like%20the%20one%20before)%20where%20you%20could%20show%20me%20how%20to%20get%20the%20data%20and%20how%20it%20should%20be%20...%20with%20a%20little%20example.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20understanding%20and%20patience%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am trying to create a Macro that when ran it will move certain rows depending on the value in the cells in a specific column. I have a spreadsheet that I need to split into two sheets depending upon the card numbers that are in one of the columns. Could someone help me with what the Macro for this would look like?

 

Thank you.

12 Replies

@Brittany0724 

  Here is a small Solution approach with VBA

 

   Private Sub Worksheet_Change (ByVal Target As Range)
     column = Target.Column
     line = Target.Row
     value = Target.Value
     If column = 11 Then
         Cells (line, value) .Value = Cells (line, 1)
     End If
     End Sub

 

 

Hope I was able to help you and would be happy to know if I could 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.

@Brittany0724  alternatively you can leave the original sheet and on the other 2 sheets just use the FILTER() function or a pivot table to populate that sheet with the corresponding data.  If you need help doing that you could supply a sample workbook (no personal/confidential info) and we could show you more specific answer(s). but in general a FILTER() would look like:

=FILTER(Sheet1!A:M,Sheet1!A:A="only this id","None Found")

where "only this id" would be a number or text that should be matched for that row to be included and A:A be changed to the column of interest. 

@Nikolino I think something like this is what I am looking for but maybe if I upload a sample file it will help some to narrow down what it would look like for me. I want to be able to run a macro that will split the list into two lists depending upon values in column B.

 

I have attached a sample spreadsheet to help explain what I'm referring to. In the sample, values "****00022", "****00031", and "****00141" in column B would correspond with one list and values "****00131", "****00231", and "****00201" in column B would correspond with a second list. What is the best way to approach splitting the big list into two lists using VBA?

@Brittany0724 

Please explain to me what exactly you would like, which data or content should be moved from which cell to which?

 

Enclosed some information.

How to select cells/ranges by using Visual Basic procedures in Excel

https://docs.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/select-cells...

 

Excuse me for the inconvenience, but need precise information in order to be able to provide you with an acceptable solution.

 

Thank you for your understanding and patience

 

Nikolino

I know I don't know anything (Socrates)

@Nikolino  No inconvenience at all. I appreciate your help. 

 

I would like it to split the list into two depending on what information is in the "Card number" Column (B). I need the other two columns for that row to move with it as well. 

 

To explain in more detail, if the "card number" (column B) is ****00022, ****00131, and ****00231 those cells and the cells in the same rows as those (the cells in column A & C) all need moved into a new sheet. The remaining "card numbers" and corresponding cells in the same rows can stay on the first sheet.

 

Hopefully this makes more sense. If I need to clarify more, please let me know.

@Brittany0724 

Sry but now I'm totally confused. Could you upload a file (like the one before) where you could show me how to get the data and how it should be ... with a little example.

 

Thank you for your understanding and patience

 

Nikolino

I know I don't know anything (Socrates)

@Nikolino 

I have attached a file to help better explain. The first sheet is the original list. I have highlighted the cells that will be used to determine which entries will go to which list. The other two sheet are what I need to end up with. Row one will always be the same on the original list and the final lists but the other rows will change depending how what values are in Column B. For example when looking at the first sheet, one week there may be more rows with "****00022" and other weeks there may be more rows with "****00231". This is why I need to do it based on the value in column B. Please let me know if there is something that I need to explain better.

 

Thank you for your help.

@Brittany0724  As I mentioned before, you can do this withOUT a macro.  Is there a reason you NEED a macro?  In the attached I put a formula into your sheet1 (and sheet2) to create those lists:

 

=FILTER(report!A:C,(RIGHT(report!$B:$B,5)=$D$1)+(RIGHT(report!$B:$B,5)=$E$1)+(RIGHT(report!$B:$B,5)=$F$1),"none")

 

For your convenience I used cells D1,E1, and F1 to define the text that should be included on that sheet.  You can easily expand on this for more options or criteria.  If you have a lot of criteria we could make it search a whole array of options but I figured for only a few options this is easier to read/understand. See attached.

@Brittany0724 

I'm not the "big pro" when it comes to pivot

(to put it mildly, my knowledge is modest, very modest :).

But I see in your plan that this can be the best way.

I will also work out a VBA macro, but first I would like to ask if this is what you want to express in the end the result?

 

I would appreciate your feedback.

 

Thank you for your understanding and patience

 

Nikolino

I know I don't know anything (Socrates)

 

@Brittany0724 

Hello, here is an additional approach with VBA that I found on the Internet.

You can customize it according to your wish.

 

Hope this will help you too.

 

Thanks for your time and patience

 

Cheers

Nikolino

I know I don't know anything (Socrates)

@Nikolino  I was going to mention pivot table option but I am also no expert on them and find them annoying to set all the properties to get them to look the way I want and because in my experiences I have had issues with them.  That said, I did take your lead and include in the attached, pivot tables on sheets 1 and 2 that basically replicate the table that @Brittany0724  has on each of those pages. (Note: I have Card Number listed first but that can be changed back to column 2)  

On sheet 1 I used the drop down menu to manually filter but the items desired and on sheet 2 I added a slicer to do the filtering.

@Nikolino If you are going to continue with a Macro solution, you will still need to have some input/strategy for identifying what card numbers need to  filter by and a way to 'run' the macro.  As a "cute" alternative you could write a macro that pastes the FILTER() formula I used above and then copy and paste values instead of actually writing the code to perform the individual selections.

 

@Nikolino  Hello my friend.  I was curious and looked at the macro file you just sent and I don't read German but from what I can work out based on the algorithm of what the macro is doing I believe it is doing the opposite of what the original poster wanted.  It appears to take a workbook with many sheets in it, in this case A-01, B-02, C-03....  each with date and then MERGING all those individual sheets of data into 1 master table.