Find content in column and sort in specific order

Andy15

Board Regular
Joined
Apr 1, 2017
Messages
56
Hi Guys

I am looking for some help with finding some content within a column and re-arranging the order of the found rows to a specific order.

To make it a bit clearer please see below


score1score2score3score4score5score6score7
texttexttexttexttexttexttext
123rednumbernumbernumbernumbernumbernumbernumber
124blunumbernumbernumbernumbernumbernumbernumber
125grnnumbernumbernumbernumbernumbernumbernumber
126oranumbernumbernumbernumbernumbernumbernumber
127blanumbernumbernumbernumbernumbernumbernumber
tomcode1code1code1code1code1code1code1
anncode2code2code2code2code2code2code2
alancode3code3code3code3code3code3code3
elliecode4code4code4code4code4code4code4
marycode5code5code5code5code5code5code5
davecode6code6code6code6code6code6code6
leecode7code7code7code7code7code7code7

<tbody>
</tbody>


The cells I need to reorder will always be in column 2 and will always be in the same order starting with "tom" and ending with "lee"

I would like to run a macro to find the relevant rows and all the relevant columns to the right and reorder them in the following order

anncode2code2code2code2code2code2
marycode5code5code5code5code5code5
elliecode4code4code4code4code4code4
alancode3code3code3code3code3code3
tomcode1code1code1code1code1code1
leecode7code7code7code7code7code7
davecode6code6code6code6code6code6

<tbody>
</tbody>

in the above examples the cells with code1, code2 are for example only, in reality they will be various numbers.

Hope this makes sense

Thanks for any help
 
Last edited:
Hi Footoo,

I am not sure why but on further testing, the code sorts as requested but when I try and save the workbook it gives an error Microsoft excel has stopped working.

I then have the options to check if there is solution or close the programme.

Thought it may help someone else that may try code.

Not sure if there is anything obvious why that would happen

Thanks
Andy

Code:
Sub FT()
Dim rng As Range, LstNum%
Set rng = [B:B].Find("tom").Resize(7)
LstNum = Application.CustomListCount + 2
Application.AddCustomList Array("ann", "mary", "ellie", "alan", "tom", "lee", "dave")
rng.EntireRow.Sort key1:=rng(1), order1:=xlAscending, Header:=xlNo, OrderCustom:=LstNum
[COLOR=#ff0000]ActiveSheet.Sort.SortFields.Clear[/COLOR]
LstNum = LstNum - 1
Application.DeleteCustomList LstNum
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Your assumptions were correct and my worksheet is as per sample, the code just seems to make the sheet flicker but nothing changes.
Then the cells in column A beside the names probably look clear but actually contain something. Out of interest, try running this code & tell us what the results are.
Code:
Sub CheckRows()
  MsgBox "'Tom' row: " & Columns("B").Find("tom").Row & vbLf & "Last row in col A with data: " & Cells(Rows.Count, 1).End(xlUp).Row
End Sub


I have tried your latest code and that is working brilliantly.

Many thanks for your help
Good news. You are very welcome. :)
 
Upvote 0

Similar threads

Forum statistics

Threads
1,215,632
Messages
6,125,913
Members
449,274
Latest member
mrcsbenson

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