Results 1 to 8 of 8

Passing a range as an argument for a subprocedure

Threaded View

  1. #1
    Registered User
    Join Date
    06-23-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2010/2007
    Posts
    34

    Passing a range as an argument for a subprocedure

    Hey guys, so i'm making a very simple project which gives the user some data fields and upon choosing 1, the macro will sort the data either in an ascending or descending manner. (note: not all of the values in the data fields are numeric, some of them require a custom list for ordering). Anyway, i'm stuck with the code because it seems that it causes an error when i pass of a range as an argument for a subprocedure. by the way, i named the ranges in excel, for example, column E is named as "Offer"

    Code:

    1 Public Sub SortValueAscending()
    2
    3 ActiveWorkbook.Worksheets("Data").Sort.SortFields.Clear
    4 ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add Key:=Range("E2:E274"), _
    5 SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    6 With ActiveWorkbook.Worksheets("Data").Sort
    7 .SetRange Range("A1").CurrentRegion
    8 .Header = xlGuess
    9 .MatchCase = False
    10 .Orientation = xlTopToBottom
    11 .SortMethod = xlPinYin
    12 .Apply
    13 End With
    14 End Sub
    15
    16 Private Sub OKButton_Click()
    17
    18 If UserForm1.OptionButton1.Value = True And UserForm1.OptionButton7.Value = True 19 Then Call SortValueAscending

    As you can see, I want to pass the "Offer" range as input in line 1 and on line 4, change the range you see labeled "E1:E174" to "Offer" and lastly, on line 19, i want to have it something like this: SortValueAscending(...) where the "Offer" column is the argument. It seems that there's an error maybe because of my syntax in passing the range as argument. Anyone can help? Thanks!
    Last edited by secondrate; 06-24-2010 at 09:50 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1