"Manage Range of object Global failed" while passing Values

abi_learn_vba

Board Regular
Joined
Nov 6, 2009
Messages
215
Hi

I am getting "Manage Range of object Global failed" error while i am passing an range value to sort a set of data. Please see my code below am i wrong somewhere?

here rng = C3:C932

Code:
Sub srt1(ByVal books As Worksheet, ByVal rng As Range, ByVal val As Double)
    books.sort.SortFields.Clear
    books.sort.SortFields.Add Key:=[COLOR=red]Range(rng),[/COLOR] SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With books.sort
        .SetRange Range("A2:T" & val)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Even if i use Activesheet.Range(rng) i am getting "Application Defined or Object defined Error"

Am i going wrong somewhere?

Thanks
-Abi
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Perhaps

Rich (BB code):
books.Sort.SortFields.Add Key:=books.Range(Rng), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
 
Upvote 0
If rng is a range defined by Set rng = whatever then try

Code:
books.Sort.SortFields.Add Key:=Rng, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,245
Members
452,900
Latest member
LisaGo

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