What is the difference between 'Select' a sheet and 'Activate' a sheet
On Oct 26, 10:58*am, norie wrote:
Actually the best way to avoid problems like you describe is not to
use Select/Activate if you can.
It's almost never needed to use them.
Instead of them try creating references to the worksheets and
workbooks you are working with.
eg
Dim wbThis As Workbook
Dim wbOpen As Workbook
Dim wsDst As Worksheet
Dim wsSrc As Worksheet
Set wbThis = ThisWorkbook ' create reference to the workbook the code
is in
set wsDst = wbThis.Worksheets("Consolidation") ' create a reference to
the worksheet 'Consolidation' in the workbook the code is in
Set wbOpen = Workbooks.Open("C:\AWorkbook.xls") ' open a workbook and
create a reference to it
Set wsSrc = wbOpen.Worksheets("Data") ' create a reference to the
workshee 'data' in the workbook that's been opened
You can now use these references in later code, and they will refer to
the worksheets/workbooks you've set them too regardless of what
worksheet/workbook is active.
Thank your for your help. I am not ignoring your answer, but I am
going to need to study your suggestion for a bit to try to understand
it. Once I grasp the concept, I will give it a try. I appreciate it.
|