Error message -sort reference is not valid

FROGGER24

Well-known Member
Joined
May 22, 2004
Messages
704
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
I am getting "sort reference is not valid. The actual rows to sort is in row 3 to last used row

VBA Code:
 With Sheets("Hours")
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      With .Range("A2", .Cells(2, Columns.Count).End(xlToLeft))
       .Resize(UsdRws).Sort .Columns(6), xlAscending, xlAscending, Header:=xlYes
         .Resize(UsdRws).Sort .Columns(6), xlAscending, .Columns(1), , xlAscending, Header:=xlYes
      End With
   End With


Appreciate help in troubleshooting
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
what
I am getting "sort reference is not valid. The actual rows to sort is in row 3 to last used row

VBA Code:
 With Sheets("Hours")
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      With .Range("A2", .Cells(2, Columns.Count).End(xlToLeft))
       .Resize(UsdRws).Sort .Columns(6), xlAscending, xlAscending, Header:=xlYes
         .Resize(UsdRws).Sort .Columns(6), xlAscending, .Columns(1), , xlAscending, Header:=xlYes
      End With
   End With


Appreciate help in troubleshooting
your code suggests you are trying to sort by column 6 and then again by column 1 over range of A2 to lastcolumn/lastrow? is that what you are trying to do?
 
Upvote 0
How about like
VBA Code:
 With Sheets("Hours")
      UsdRws = .Range("A" & Rows.count).End(xlUp).Row
      With .Range("A2", .Cells(2, Columns.count).End(xlToLeft))
         .Resize(UsdRws).Sort .Columns(6), xlAscending, .Columns(1), , xlAscending, Header:=xlYes
      End With
   End With
 
Upvote 0
sorry for delay in responding the code worked. Thank you
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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