sort button macro issue

bluepenink

Well-known Member
Joined
Dec 21, 2010
Messages
585
hello all

having some problem for some odd reason with my sort button macro.

i recently added 20 extra (blank) rows to the worksheet, and the macro for some odd reason is not sorting the data? ive been staring at my screen for an hour, no idea whats happening. can someone pls advise

Code:
Sub KPI()
Range("C11:R" & Range("C11").End(xlDown).Row).Sort Key1:=Range("E12"), Order1:=xlDescending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
        
Range("I7") = "Sorted by: Send Report"
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Range("C11").End(xlDown).Row is not going to pick up the blank rows. Did you want them sorted?
 
Upvote 0
I'm not understanding the significance of the 20 blank rows then. Are they in the middle of your data?
 
Upvote 0
hey bud

im behind a firewall at work so i cant post a file, other than another excel forum that i know. so i have posted a file there.

http://www.excelforum.com/excel-general/784168-sort-button-not-working.html

the individual mentioned, bc column c is being derived from another worksheet (Data) that is it factoring into the issue.

to answer ur Q:
the blank rows are at the end, so not sure if that should cause an issue.
 
Upvote 0
based on some great help, i tried the following code

Code:
Sub SE()
Worksheets("Data").Range("C11:R" & Range("C11").End(xlDown).Row).Sort Key1:=Range("C12"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
 
Range("I7") = "Sorted by: SE"
End Sub

but getting an error msg:
"the sort reference is not valid. make sure its w/in the data you want to sort, and the first sort by box isnt the same or blank. "
 
Upvote 0
YOu haven't qualified all the Range statements:
Code:
Sub SE()
With Worksheets("Data")
   .Range("C11:R" & .Range("C11").End(xlDown).Row).Sort Key1:=.Range("C12"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
.Range("I7") = "Sorted by: SE"
End With
End Sub
 
Upvote 0
hello

i had to change the range from C:CS as my worksheet contains data till column CS.

that appears to sort data on my "Master" worksheet - where the sort button is....and the "Data" worksheet.

however, i have other sort buttons on the "Master" worksheet i.e. revenue, appointments set (and i have a sort to sort them lowest to greatest).

i.e. this is my code, but it's failing to work
Code:
Sub Branch()
Range("C11:R" & Range("C11").End(xlDown).Row).Sort Key1:=Range("D12"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
        
Range("I7") = "Sorted by: Branch"
End Sub

the issue is....my first column of data on the "Master" worksheet contains the following formula

=IF(ISTEXT(INDIRECT("Data!C" & (12+ROWS($1:1))-1)),INDIRECT("Data!C" & (12+ROWS($1:1))-1),"")

^which appears to be causing all the problems...any suggestions? pls and thx u
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,354
Members
449,155
Latest member
ravioli44

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