Sort leading to debug error... any thoughts?

braindiesel

Well-known Member
Joined
Mar 16, 2009
Messages
571
Office Version
  1. 365
  2. 2019
  3. 2010
Platform
  1. Windows
I have the following code working as part of a macro without any issue... of course, when I get to my client, I get a debug error...
The topRow and botRow variables are storing numbers and in debug mode, when I hover over them, the correct numbers are showing.
Any thoughts on a better way to write this or am I missing something?

ActiveWorkbook.Worksheets("REPORT5").Sort.SortFields.Add2 Key:=Range( _
"D" & topRow & ":D" & botrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("REPORT5").Sort.SortFields.Add2 Key:=Range( _
"E" & topRow & ":E" & botrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
There is no Add2 method, and if REPORT5 is not the active sheet you'll get a run-time error.

Code:
  With Worksheets("REPORT5")
    .Sort.SortFields.Add Key:=.Cells(toprow, "D")
    .Sort.SortFields.Add Key:=.Cells(toprow, "E")
  End With
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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