Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 313
Default VBA Variable Range Sort

I am trying to sort a variable range with a static first cell ("A4"). How do
I use a variable reference to the end range in the sort statement? Here is
what I am trying to use but it gives me a syntax error.

wsPh.Application.Goto Reference:="R4C1"
wsPh.Range("a4:("r" & EMcnt)").Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending,
Key2:=Range("R4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default VBA Variable Range Sort

Get the last row using

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

and then

wsPh.Range("A4:R" & lngLastRow).Select

--
If this post helps click Yes
---------------
Jacob Skaria


"Tony" wrote:

I am trying to sort a variable range with a static first cell ("A4"). How do
I use a variable reference to the end range in the sort statement? Here is
what I am trying to use but it gives me a syntax error.

wsPh.Application.Goto Reference:="R4C1"
wsPh.Range("a4:("r" & EMcnt)").Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending,
Key2:=Range("R4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 313
Default VBA Variable Range Sort

I am now using the following code which puts in the last row (I am gloing to
be adding more data after this group has been sorted). I now recive an
"method or data member not found" on the next line(.Selection.Sort....):

wsPh.Range("a4:r" & EBottom).Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending, Key2:=Range("R" &
EBottom) _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal

"Jacob Skaria" wrote:

Get the last row using

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

and then

wsPh.Range("A4:R" & lngLastRow).Select

--
If this post helps click Yes
---------------
Jacob Skaria


"Tony" wrote:

I am trying to sort a variable range with a static first cell ("A4"). How do
I use a variable reference to the end range in the sort statement? Here is
what I am trying to use but it gives me a syntax error.

wsPh.Application.Goto Reference:="R4C1"
wsPh.Range("a4:("r" & EMcnt)").Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending,
Key2:=Range("R4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA Variable Range Sort

Remove the dot in front of .Selection.sort

Or stop the selection:

with wsPh
with .Range("a4:r" & EBottom)
.cells.Sort Key1:=.columns(9), Order1:=xlAscending, _
Key2:=.columns(18), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=false, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
end with
end with

Also, I bet you know if your data has headers. I wouldn't let the code guess.
Use xlyes or xlno.



Tony wrote:

I am now using the following code which puts in the last row (I am gloing to
be adding more data after this group has been sorted). I now recive an
"method or data member not found" on the next line(.Selection.Sort....):

wsPh.Range("a4:r" & EBottom).Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending, Key2:=Range("R" &
EBottom) _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal

"Jacob Skaria" wrote:

Get the last row using

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

and then

wsPh.Range("A4:R" & lngLastRow).Select

--
If this post helps click Yes
---------------
Jacob Skaria


"Tony" wrote:

I am trying to sort a variable range with a static first cell ("A4"). How do
I use a variable reference to the end range in the sort statement? Here is
what I am trying to use but it gives me a syntax error.

wsPh.Application.Goto Reference:="R4C1"
wsPh.Range("a4:("r" & EMcnt)").Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending,
Key2:=Range("R4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default VBA Variable Range Sort

With wsPh
..Range("a4:r" & EBottom).Sort Key1:=.Range("I4"), Order1:=xlAscending,
Key2:=.Range("R" &
EBottom) _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2
_
:=xlSortNormal
End With

HTH,
Bernie
MS Excel MVP

"Tony" wrote in message
...
I am now using the following code which puts in the last row (I am gloing
to
be adding more data after this group has been sorted). I now recive an
"method or data member not found" on the next line(.Selection.Sort....):

wsPh.Range("a4:r" & EBottom).Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending, Key2:=Range("R"
&
EBottom) _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

"Jacob Skaria" wrote:

Get the last row using

lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

and then

wsPh.Range("A4:R" & lngLastRow).Select

--
If this post helps click Yes
---------------
Jacob Skaria


"Tony" wrote:

I am trying to sort a variable range with a static first cell ("A4").
How do
I use a variable reference to the end range in the sort statement? Here
is
what I am trying to use but it gives me a syntax error.

wsPh.Application.Goto Reference:="R4C1"
wsPh.Range("a4:("r" & EMcnt)").Select
.Selection.Sort Key1:=Range("I4"), Order1:=xlAscending,
Key2:=Range("R4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal




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
How do I sort between worksheets depending on variable Miriaham Excel Worksheet Functions 1 September 30th 08 11:34 PM
Variable Column Sort Bernie New Users to Excel 1 December 29th 06 11:09 PM
How do I use a variable in a sort macro APealin Excel Worksheet Functions 0 October 12th 06 03:40 PM
Automatic Sort for variable Ranges bman342 Excel Worksheet Functions 2 June 27th 06 08:51 PM
Sort : how can I use a variable in a VB sort function? El Bee Excel Worksheet Functions 3 February 16th 06 09:34 PM


All times are GMT +1. The time now is 12:41 AM.

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

About Us

"It's about Microsoft Excel"