Struggling with Sort Descending sub routine in VBA

Lauren Ward

New Member
Joined
Dec 9, 2019
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Greetings all - relatively new to VBA, and struggling with a routine that has worked before.
I usually would copy and paste and adjust the range and it would work fine, but now it's not sorting at all.
The item is a list of statements, with a $ value and % value. I want to sort by descending value on the % (K) when the spreadsheet it activated.

Here is what I had ... why isn't it working?
Thanks in advance

Range("C69:K76").Select
Selection.Sort Key1:=Range("k64"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("j8").Select
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hello Lauren,

Your sort key must be in the selected range. K64 is not part of the range "C69:K76".
 
Upvote 0
OK, I adjusted the to be K76 (which is the percentage I would like to sort on) but it is not running / activating ?
 
Upvote 0
Where is the your macro located and what activates it?
 
Upvote 0
This is the full text of the macro. It should be activated when I change tabs but that's not happening. It's located within the VBA code of one of the worksheets. As you can tell, I didn't write the wording, but have been able to make it work in the past ...


Private Sub Worksheet_Activate()

Dim indx As Integer, DoHide As Boolean

Application.ScreenUpdating = False
ActiveSheet.DisplayPageBreaks = False
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False

For indx = 2 To 220
DoHide = (Cells(indx, 1) = 0) And (Cells(indx, 1) <> "")
Cells(indx, 1).Rows.Hidden = DoHide
Next indx


Range("A69:k76").Select
Selection.Sort Key1:=Range("k69"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("j8").Select

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False
Application.ScreenUpdating = True

End Sub

Sub OLEObjects2()
'Delete all ActiveX controls(Control Toolbox)or linked or embedded OLE objects
On Error Resume Next
ActiveSheet.OLEObjects.Visible = True
ActiveSheet.OLEObjects.Delete
On Error GoTo 0
End Sub
 
Upvote 0
The only thing I can think of is that row for Key1 is hidden.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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