ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   error in sorting (https://www.excelbanter.com/excel-programming/295910-error-sorting.html)

hans[_3_]

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



Pete McCOsh

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



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com