macro to sort by multiple columns with no header, on a dynamic range selected using an input box and no header

Rackette

New Member
Joined
Jul 2, 2019
Messages
37
Hi, and thank you for any help and assistance.
My spreadsheet has 5 columns and about 200 rows. One of the columns is Name, then Start time, another is end time, a 4th is location, a 5th is role.
Initially, I sort by start time and then every time there is a change in start time, I have to insert a blank row so that that change is more noticeable to those looking at the printout...which means I can't us a header row when sorting.

What I need help with is:
I need to use an input box to select the range where the 'start time' = 1300.
Then, within that input box range, I need to sort by 'location' and then 'role', and then by 'name'.
So that the 1300 start time range gets sorted alphabetically by location, and within each different location, it is sorted alphabetically by role, and then, within each role, sorted alphabetically by name.

This is what it starts as:
Already sorted by start time and then alphabetically by name; blank row between each change in start time.
For some reason there is a HUGE gap between the bottom of this grid and the start of the next one...please scroll.

Name
Start TimeEnd TimeLocationRole
James10001100Annexb
John10001100Annexa
Mary10001115Bridgeb
Peggy10001115Shedb
Ashley13001330Shedb
Audrey13001330Bridgeb
Hermi13001330Annexa
Henry13001330Bridgea
Marcel13001330Annexd
Phillip13001330Annexa
Garth13151400Annexd
Mable13151400Shedd

<tbody>
</tbody>

























I need to make changes to the 1300 'start time' block but all the other ranges on the sheet I DON'T want to make any changes to.
The 1300 'selected-by-an-input-box' range needs to end up like this after running the macro:

Hermi13001330Annexa
Phillip13001330Annexa
Marcel13001330Annexd
Henry13001330Bridgea
Audrey13001330Bridgeb
Ashley13001330Shedb

<tbody>
</tbody>
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this:-
NB:- If you are always going to search by 1300 you don't really need an input box !!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG05Jul28
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, MyNum [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
MyNum = InputBox("Enter number", "Number", "Type your number here")
[COLOR="Navy"]Set[/COLOR] Rng = Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Areas
    [COLOR="Navy"]If[/COLOR] Dn(1).Offset(, 1) = MyNum [COLOR="Navy"]Then[/COLOR]
            Dn.Resize(, 5).Sort Key1:=Dn(1).Offset(, 3), Order1:=xlAscending, _
            Key2:=Dn(1).Offset(, 4), Order2:=xlAscending, _
            Key3:=Dn(1), Order3:=xlAscending, _
            Header:=xlNo
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
Regards Mick
 
Upvote 0
I appreciate you taking the time to help me, MickG.
When I tried to run it, it said it needed an 'end sub', so I stuck one in down below the "Next Dn".
But when I run it on some data, nothing gets sorted.
When the input box pops up, I enter my data range which was A8:D11.
Is there a problem if there are blank rows between the different 'start times'?
Thank you!
-Christine
 
Upvote 0
It works much better when *I* do what I'm supposed to. :)
What you guys do by taking time to help on here makes SO much difference for those of us who don't know how to do it.
Thank you for taking the time to do what you do here. :)
 
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,803
Members
449,261
Latest member
Rachel812321

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