ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem coding a Sort (https://www.excelbanter.com/excel-programming/310800-problem-coding-sort.html)

Peter Chatterton[_2_]

Problem coding a Sort
 
How do I code this so as to use an Integer containing 7 for the column?
dataRange.Sort Key1:=Range("G5")

(Set dataRange = ActiveWorkbook.Sheets("source"). _
( Range(Cells(iStartDataRow, 1), _
( Cells(iMaxRowNumb, iMaxColNumb))

Thanks,
Peter.



Tom Ogilvy

Problem coding a Sort
 
icol = 7
dataRange.Sort Key1:=worksheets("Source").Cells(5,icol)

--
Regards,
Tom Ogilvy


"Peter Chatterton" wrote in message
. ..
How do I code this so as to use an Integer containing 7 for the column?
dataRange.Sort Key1:=Range("G5")

(Set dataRange = ActiveWorkbook.Sheets("source"). _
( Range(Cells(iStartDataRow, 1), _
( Cells(iMaxRowNumb, iMaxColNumb))

Thanks,
Peter.





Peter Chatterton[_2_]

Problem coding a Sort
 
Hi Tom,

Dim iCol As Integer
iCol = 7
dataRange.Sort Key1:=ActiveWorkbook.Sheets("source").Cells(5,
iCol)

When I try it I get "Appl-def'd or Obj-def'd error".

BTW what is the 5 for?

Thanks,
Peter.

"Tom Ogilvy" wrote in message
...
icol = 7
dataRange.Sort Key1:=worksheets("Source").Cells(5,icol)

--
Regards,
Tom Ogilvy


"Peter Chatterton" wrote in message
. ..
How do I code this so as to use an Integer containing 7 for the column?
dataRange.Sort Key1:=Range("G5")

(Set dataRange = ActiveWorkbook.Sheets("source"). _
( Range(Cells(iStartDataRow, 1), _
( Cells(iMaxRowNumb, iMaxColNumb))

Thanks,
Peter.







Peter Chatterton[_2_]

Problem coding a Sort
 
UPDATE TO MY REPLY
(couldn't reply to myself)

I took the As Integer off my defn of iCol and it worked!

But haven't figured it out yet.

Thanks,
Peter.


"Tom Ogilvy" wrote in message
...
icol = 7
dataRange.Sort Key1:=worksheets("Source").Cells(5,icol)

--
Regards,
Tom Ogilvy


"Peter Chatterton" wrote in message
. ..
How do I code this so as to use an Integer containing 7 for the column?
dataRange.Sort Key1:=Range("G5")

(Set dataRange = ActiveWorkbook.Sheets("source"). _
( Range(Cells(iStartDataRow, 1), _
( Cells(iMaxRowNumb, iMaxColNumb))

Thanks,
Peter.








All times are GMT +1. The time now is 12:19 PM.

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