Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a large set of books and loads of macros - they all work OK, but I've
been trying to tweak some of them to make them go a little faster. I've discovered that sometimes adding the With - End With construct to a macro can make it go faster (as I expected) but othertimes it makes it go slower. What are the rules? Here is an example of a change that made things slower (part of a function)... Original: Set rng = Workbooks("data.xls").Worksheets("students").Range ("1:1") lkcol = Application.WorksheetFunction.Match(lookupkey, rng, 0) rtncol = Application.WorksheetFunction.Match(rtnkey, rng, 0) With Workbooks("data.xls").Worksheets("students") Set rng2 = .Range(.Cells(1, lkcol), .Cells(65535, lkcol)) End With rtnrow = Application.WorksheetFunction.Match(lookupval, rng2, 0) Sinfo = Workbooks("data.xls").Worksheets("students").Cells (rtnrow, rtncol) Revised, and markedly slower: With Workbooks("data.xls").Worksheets("students") Set rng = .Range("1:1") lkcol = Application.WorksheetFunction.Match(lookupkey, rng, 0) rtncol = Application.WorksheetFunction.Match(rtnkey, rng, 0) Set rng2 = .Range(.Cells(1, lkcol), .Cells(65535, lkcol)) rtnrow = Application.WorksheetFunction.Match(lookupval, rng2, 0) Sinfo = .Cells(rtnrow, rtncol) End With -- Adrian D.Bailey, Information and Systems Manager, Dept.Human Sciences Loughborough University, Loughborough Leics, LE11 3TU, UK. Tel: 01509 223007 Fax: 01509 223940 Community Warden, Storer and Burleigh Areas. Out-of-hours Tel: 01509 563263 -- |