sort macro...not working

bluepenink

Well-known Member
Joined
Dec 21, 2010
Messages
585
Hello

below is my code, just having some difficulty with defining the sheet name portion...at least taht is whre the error is occuring:

Code:
Sub EmployeeName()
    ActiveSheet.Index = Sheet1.Index
    Range("C6").CurrentRegion.Sort Key1:=Range("D7"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
       
Range("F5") = "Sorted by: Employee Name"
End Sub

row 6 has the headers....so the header range is C6:N6

much appreciated!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi. Perhaps

Code:
Sub EmployeeName()
With Sheet1
    .Range("C6").CurrentRegion.Sort Key1:=.Range("D7"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
       
    .Range("F5") = "Sorted by: Employee Name"
End With
End Sub
 
Upvote 0
Hello thxs for ur response.

my data is in range (C7:N1100)

Im trying to sort by a field aka employee name, and then branch name
employee name is column D
Branch name is E

both will be seperate macros buttons. thx u
 
Upvote 0
Try

Code:
Sub EmployeeName()
With Sheet1
    .Range("C7:N1100").Sort Key1:=.Range("D7"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
       
    .Range("F5") = "Sorted by: Employee Name"
End With
End Sub
 
Upvote 0
perfect, thx you so much!!!!!!! ur awesome

i just had to change the range to C6:N1100 as the header was in range row 6.

thxs again!
 
Upvote 0
hello quick question

how can i make the macro say...."Sorted by: None"....when a macro for sort has not been clicked? thxs!
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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