Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default problem passing an argument to a sub

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default problem passing an argument to a sub

Hi,

Make the following change to the sorter procedure by delcaring the
parameters as strings......

Public Sub sorter(RangeStart As String, SortKey As String)

Then call the procedure using......

Call sorter("B3", "S3")

--
Cheers
Nigel



"natanz" wrote in message
...
I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default problem passing an argument to a sub

Hi,
Use Call Sorter("B3","S3")

HTH

"natanz" wrote:

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default problem passing an argument to a sub

Hi,
Call Sorter("B3","S3")

HTH

"natanz" wrote:

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default problem passing an argument to a sub

Call sorter("B3", "S3")
Stefi


€žnatanz€ť ezt Ă*rta:

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default problem passing an argument to a sub

Call sorter("B3","S3")
Regards, Stefi


€žnatanz€ť ezt Ă*rta:

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default problem passing an argument to a sub

You need to supply the cell addresses as strings, the way you wrote it, so
call it as:
Sorter("b3","s3")

"natanz" wrote:

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.

  #8   Report Post  
Posted to microsoft.public.excel.programming
bac bac is offline
external usenet poster
 
Posts: 76
Default problem passing an argument to a sub

Probably because the call is trying to pass variables named b3 and s3 that
don't exist?

in the Calling routine

Dim RangeStart, SortKey as Range

Then set them to the desired values:

RangeStart = "A3"
SortKey = "S3"

then call the sub:

sorter RangeStart, SortKey (No ())

BAC


"natanz" wrote:

I have the following code that I use to sort a range of data.

Public Sub sorter()
Range("b3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("S3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I am trying to rewrite it, so that I can pass two arguments to it, the
first argument would be in place of the "b3" in the second line, and
the other argument would replace "S3" in the fifth line of the code
above.

now my code looks like this:

Public Sub sorter(RangeStart, SortKey)
Range(RangeStart, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range(SortKey), Order1:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False,Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

and i was using a call to this procedure that looks like this:
sorter (b3, s3)

but that doesn't work. Can someone tell me what i am doing wrong? I
am new at this, and learning on my own so any help is appreciated. Can
I pass a literal as an argument to a procedure? Thanks in advance.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a UDF as an argument to a UDF puff Excel Discussion (Misc queries) 3 February 23rd 06 09:46 PM
passing argument problem ?? ricksimm[_2_] Excel Programming 1 June 14th 05 12:30 AM
Passing argument to excel rci Excel Programming 2 February 25th 05 01:27 PM
Passing argument to another Sub Roman Excel Programming 6 February 1st 05 09:17 PM
Passing an argument to a quote Zach Excel Programming 1 July 25th 03 01:00 AM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"