Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Vj Vj is offline
external usenet poster
 
Posts: 54
Default Sorting Sheet1 from Sheet2

Hi,

I have data in sheet1 in col A, B and C and I need to sort the data when the workbook is not active(either addIn) or from other sheet(Sheet2). The following is the code i am using but its gives me error.

Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A25:C44")
'If sortcriteria is None then dont do anything
'If sortcriteria is Ascending then do Ascending sorting
If sortCriteria = "Ascending" Then rng.sort Key1:=Range(rng.Columns(ColNo).Address), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom: Exit Sub

Can somebody suggest me a way out?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Sorting Sheet1 from Sheet2

VJ,

Your key isn't in the actual table when your sheet isn't active.

Key1:=Range(rng.Columns(ColNo).Address)

sets the key to a cell on the activesheet.

Change the key to something like

Key1:=rng.Cells(1,ColNo)

HTH,
Bernie
MS Excel MVP

"VJ" wrote in message
...
Hi,

I have data in sheet1 in col A, B and C and I need to sort the data when

the workbook is not active(either addIn) or from other sheet(Sheet2). The
following is the code i am using but its gives me error.

Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A25:C44")
'If sortcriteria is None then dont do anything
'If sortcriteria is Ascending then do Ascending sorting
If sortCriteria = "Ascending" Then rng.sort

Key1:=Range(rng.Columns(ColNo).Address), _
Order1:=xlAscending,

Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom: Exit

Sub

Can somebody suggest me a way out?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sorting Sheet1 from Sheet2

If sortCriteria = "Ascending" Then rng.sort
Key1:=rng.Columns(ColNo).Cells(1,1), _
Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom: Exit Sub

--
Regards,
Tom Ogilvy


"VJ" wrote in message
...
Hi,

I have data in sheet1 in col A, B and C and I need to sort the data when

the workbook is not active(either addIn) or from other sheet(Sheet2). The
following is the code i am using but its gives me error.

Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A25:C44")
'If sortcriteria is None then dont do anything
'If sortcriteria is Ascending then do Ascending sorting
If sortCriteria = "Ascending" Then rng.sort

Key1:=Range(rng.Columns(ColNo).Address), _
Order1:=xlAscending,

Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom: Exit

Sub

Can somebody suggest me a way out?

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
Vj Vj is offline
external usenet poster
 
Posts: 54
Default Sorting Sheet1 from Sheet2

Thanks Bernie and Tom.

"Tom Ogilvy" wrote:

If sortCriteria = "Ascending" Then rng.sort
Key1:=rng.Columns(ColNo).Cells(1,1), _
Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom: Exit Sub

--
Regards,
Tom Ogilvy


"VJ" wrote in message
...
Hi,

I have data in sheet1 in col A, B and C and I need to sort the data when

the workbook is not active(either addIn) or from other sheet(Sheet2). The
following is the code i am using but its gives me error.

Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A25:C44")
'If sortcriteria is None then dont do anything
'If sortcriteria is Ascending then do Ascending sorting
If sortCriteria = "Ascending" Then rng.sort

Key1:=Range(rng.Columns(ColNo).Address), _
Order1:=xlAscending,

Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom: Exit

Sub

Can somebody suggest me a way out?

Thanks




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
copy data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Excel Discussion (Misc queries) 6 February 27th 09 09:48 PM
how do copy "sheet1!A1+1 in sheet2 to sheet 3 and get "sheet2!A1+ Dany Excel Discussion (Misc queries) 5 April 16th 07 03:27 AM
[=Sheet1!A1] - if i use Column A1 ('Sheet1') / A2 ('Sheet2') Lawrence C H Tan Excel Worksheet Functions 0 January 19th 07 08:29 PM
How to reference C5, D5, E5 from sheet2 in A1, A2, A3 of sheet1? Mark Excel Worksheet Functions 1 October 11th 06 09:46 AM
VALUES CORRESPONDING FROM SHEET1 / SHEET2 R.Deurs Excel Programming 3 May 17th 04 01:52 PM


All times are GMT +1. The time now is 04:12 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"