ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Coding Equivalent of CRL-A? (https://www.excelbanter.com/excel-programming/447166-coding-equivalent-crl.html)

Caveman1957

Coding Equivalent of CRL-A?
 
When in a worksheet I can manually select all cells by doing a control-A is there an equivalent I can use when coding?

I tried recording a macro and it just enters the particular range that was selected so is not dynamic in the way control-A is.

I am trying to do this as a precondition before doing a sort on all the data.

Caveman1957

Quote:

Originally Posted by Caveman1957 (Post 1605654)
When in a worksheet I can manually select all cells by doing a control-A is there an equivalent I can use when coding?

I tried recording a macro and it just enters the particular range that was selected so is not dynamic in the way control-A is.

I am trying to do this as a precondition before doing a sort on all the data.

I have come up with this code below but now am having a problem with what to put in the .SetRange to use column A in the UsedRange selection.

ActiveWorkbook.Worksheets("SS").Sort.SortFields.Cl ear
ActiveWorkbook.Worksheets("SS").Sort.SortFields.Ad d Key:=Sheet8.UsedRange, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SS").Sort
.SetRange Range(?????????)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Caveman1957

Quote:

Originally Posted by Caveman1957 (Post 1605655)
I have come up with this code below but now am having a problem with what to put in the .SetRange to use column A in the UsedRange selection.

ActiveWorkbook.Worksheets("SS").Sort.SortFields.Cl ear
ActiveWorkbook.Worksheets("SS").Sort.SortFields.Ad d Key:=Sheet8.UsedRange, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SS").Sort
.SetRange Range(?????????)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Turned out I had the ranges back to front in my mind :P

Code works if set as follows

ActiveWorkbook.Worksheets("SS").Sort.SortFields.Cl ear
ActiveWorkbook.Worksheets("SS").Sort.SortFields.Ad d Key:=Range("A:A"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SS").Sort
.SetRange Sheet8.UsedRange
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Hope this helps someone else save some pain

Claus Busch

Coding Equivalent of CRL-A?
 
Hi,

Am Wed, 19 Sep 2012 09:25:55 +0000 schrieb Caveman1957:

When in a worksheet I can manually select all cells by doing a control-A
is there an equivalent I can use when coding?


try:
ActiveSheet.UsedRange.Select


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

Living the Dream

Coding Equivalent of CRL-A?
 
On 19/09/2012 11:53 PM, Claus Busch wrote:
Hi,

Am Wed, 19 Sep 2012 09:25:55 +0000 schrieb Caveman1957:

When in a worksheet I can manually select all cells by doing a control-A
is there an equivalent I can use when coding?


try:
ActiveSheet.UsedRange.Select


Regards
Claus Busch


Try:

Cells.Select

HTH
Mick.


All times are GMT +1. The time now is 07:58 AM.

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