Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm working at the moment on speeding up my code (already in use for
18 months) and therefore want to limit focus changes between workbooks, sheets, etc. Elsewhere in this newsgroup I've explained why TurningOff ScreenUpdate isn't an option for me; in short the resulting screen after turning it back on goes all haywire. Using With ... End With, really does speed up things considerably. So far however I've not managed to do a Sort without first activating the sheet to sort. As such the following code only works when Worksheet 'def' in workbook 'abc' is activated. Activating another workbook, or for that matter another sheet in this workbook will lead to error 1004. Sub Macro1() ' With Workbooks("Abc.xls").Worksheets("def").Range("ghi" ) .Sort Key1:=Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal End With End Sub The same happens when the With code is more or less implied through: Workbooks("Abc.xls").Worksheets("def").Range("ghi" ).Sort _ Key1:=Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal Any ideas as to why this won't work? Thanks, Leo Elbertse |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try the following:
Sub Macro1() ' With Workbooks("Abc.xls").Worksheets("def") .Range("ghi").Sort Key1:=.Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal End With End Sub The key has to be in the range to be sorted Kevin Beckham -----Original Message----- I'm working at the moment on speeding up my code (already in use for 18 months) and therefore want to limit focus changes between workbooks, sheets, etc. Elsewhere in this newsgroup I've explained why TurningOff ScreenUpdate isn't an option for me; in short the resulting screen after turning it back on goes all haywire. Using With ... End With, really does speed up things considerably. So far however I've not managed to do a Sort without first activating the sheet to sort. As such the following code only works when Worksheet 'def' in workbook 'abc' is activated. Activating another workbook, or for that matter another sheet in this workbook will lead to error 1004. Sub Macro1() ' With Workbooks("Abc.xls").Worksheets("def").Range ("ghi") .Sort Key1:=Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal End With End Sub The same happens when the With code is more or less implied through: Workbooks("Abc.xls").Worksheets("def").Range("ghi ").Sort _ Key1:=Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal Any ideas as to why this won't work? Thanks, Leo Elbertse . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Whoah,
what a rookie mistake! Thanks Kevin, Leo On Sun, 28 Dec 2003 09:03:41 -0800, "Kevin Beckham" wrote: Try the following: Sub Macro1() ' With Workbooks("Abc.xls").Worksheets("def") .Range("ghi").Sort Key1:=.Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal End With End Sub The key has to be in the range to be sorted Kevin Beckham -----Original Message----- I'm working at the moment on speeding up my code (already in use for 18 months) and therefore want to limit focus changes between workbooks, sheets, etc. Elsewhere in this newsgroup I've explained why TurningOff ScreenUpdate isn't an option for me; in short the resulting screen after turning it back on goes all haywire. Using With ... End With, really does speed up things considerably. So far however I've not managed to do a Sort without first activating the sheet to sort. As such the following code only works when Worksheet 'def' in workbook 'abc' is activated. Activating another workbook, or for that matter another sheet in this workbook will lead to error 1004. Sub Macro1() ' With Workbooks("Abc.xls").Worksheets("def").Range ("ghi") .Sort Key1:=Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal End With End Sub The same happens when the With code is more or less implied through: Workbooks("Abc.xls").Worksheets("def").Range("gh i").Sort _ Key1:=Range("A2"), Order1:=xlDescending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal Any ideas as to why this won't work? Thanks, Leo Elbertse . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting only specific rows for a Sort | Excel Discussion (Misc queries) | |||
Conflicts with autorefresh in pivot table activating sheet protect | Excel Discussion (Misc queries) | |||
Problem in activating a sheet | Excel Programming | |||
Selecting/Activating Control Tools Combobox on Sheet | Excel Programming | |||
Selecting or Activating a cell. | Excel Programming |