Find first instance of a string then "group" all remaining rows together

john69

New Member
Joined
Dec 19, 2010
Messages
11
Hello all -

What I want to accomplish is to group the City A's in rows 5 & 6 to 2 & 3 by finding the first instance of a string in the text column and then finding the remaining ones in the rest of the range and moving the entire row(s) up. Once it groups CITY A, then it will search for CITY B, group all of them, then CITY C, etc.
There can be up to several unique text values in a list and up to 600-700 rows of total data.

I hope I have explained it well enough. Thank you in advance for you consideration in helping me with this one!

Before:
[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]ID (col F)
[/TD]
[TD]TEXT (col N)
[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]CITY A[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]CITY B[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]CITY C[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]CITY A[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]CITY A[/TD]
[/TR]
</tbody>[/TABLE]

After:
[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]TEXT[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]CITY A[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]CITY A[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]CITY A[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]CITY B[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]CITY C[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
From the information given, it seems the simplest answer is to select all the data you want arranged this way and sort it by column N.
 
Upvote 0
From the information given, it seems the simplest answer is to select all the data you want arranged this way and sort it by column N.

Thank you for the reply, but it really isn't that simple. The actual list is for a production line that produces product starting from the west coast and with the exception of grouping the cities together, the first instance of each city must remain where its at and I must move the remaining ones "up" to the first one.
If I just sort by the city, then I lose the "first instance" of each city for production. In a way, it would be like taking a copy of (the first instance) of each unique city name, then inserting the remainder of them just below (along with entire row of data). I apologize I can't explain it any better.
 
Upvote 0
...the first instance of each city must remain where its at and I must move the remaining ones "up" to the first one.

Relative to what? Must it remain in a specific row on the sheet (and how will your copy-and-insert affect that?), or do you mean that it must still be where it is relative to the other production from that city?


...If I just sort by the city, then I lose the "first instance" of each city for production...

Not sure what you mean here. You can sort by city first, then by date/time to keep them in chronological order.


A few rows of data, fictionalized to protect your actual data, would probably clear things up. A small set showing what you start with and what you want to end with would be helpful.
 
Upvote 0

Forum statistics

Threads
1,223,635
Messages
6,173,479
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top