excelbytes
Active Member
- Joined
- Dec 11, 2014
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
I have a workbook called "Consolidated HR Report". In it there are 4 worksheets. One is called "Training". I have another workbook called "AllTraining", which has between 8 to 11 worksheets. Examples of the names of those worksheets are "Co_Training", "Fi_Training", "Gr_Training", etc. I open both workbooks and run the code that's in the Consolidated workbook, and what that does is goes into each of the 8 to 11 worksheets in the AllTraining workbook and copies the data into specific areas of the Consolidated workbook. However, There aren't always all of the 11 "locations" in the "AllTraining" workbook. How do I modify the code to check to see if that worksheet is in the "AllTraining" workbook, and if not, skip to the next worksheet?
I hope that makes sense. Here is a partial sample of the VBA code:
I hope that makes sense. Here is a partial sample of the VBA code:
VBA Code:
Sheets("Training").Select
Range("A1").Select
Windows("AllTraining.xlsm").Activate
Sheets("Co_Training").Select
Range("C7:N29").Select
Selection.Copy
Windows("Consolidated HR Report.xlsm").Activate
Range("C35").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Training").Select
Range("A1").Select
Windows("AllTraining.xlsm").Activate
Sheets("Fi_Training").Select
Range("C7:N29").Select
Selection.Copy
Windows("Consolidated HR Report.xlsm").Activate
Range("C63").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Training").Select
Range("A1").Select
Windows("AllTraining.xlsm").Activate
Sheets("Gr_Training").Select
Range("C7:N29").Select
Selection.Copy
Windows("Consolidated HR Report.xlsm").Activate
Range("C91").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Training").Select
Range("A1").Select
Windows("AllTraining.xlsm").Activate