Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default error in sorting

I want a macro to sort a number of collums
I use the following program

Range(Cells(2, ccol), Cells(i - 1, ccol + 1)).Select

Selection.Sort Key1:=Range(Cells(1, ccol)), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

ccol is the column number and i is the deph
I get an error in the last line.

The error wil be in the "Key1:=Range(Cells(1, ccol))"

What am i doing wrong

Greetings Hans


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default error in sorting

Hans,

if you're using "Cells" as a reference inside "Range" I
think you have to have have two cell references for a
start and an end point, e.g:

Range(cells(1,1),cells(2,2))

In your code, you would have to use:

Range(Cells(1, ccol),cells(1,ccol))

But, if your pnly referencing a single cell, it would be
simpler to do away with the "Range" part and simply have:

Key1:= Cells(1, ccol)

Cheers, Pete.

-----Original Message-----
I want a macro to sort a number of collums
I use the following program

Range(Cells(2, ccol), Cells(i - 1, ccol + 1)).Select

Selection.Sort Key1:=Range(Cells(1, ccol)),

Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

ccol is the column number and i is the deph
I get an error in the last line.

The error wil be in the "Key1:=Range(Cells(1, ccol))"

What am i doing wrong

Greetings Hans

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
Formula Error When Sorting carl Excel Worksheet Functions 1 November 7th 11 09:04 PM
VBA Sorting Error Scott Halper Excel Worksheet Functions 1 March 19th 08 01:27 PM
Sorting error Daminc Excel Discussion (Misc queries) 4 April 11th 06 11:39 AM
sorting error ananga Excel Discussion (Misc queries) 2 June 30th 05 04:21 PM
sorting error abstsogds Excel Worksheet Functions 2 December 6th 04 07:19 PM


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