excel in courses - a copying sheets existing

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » excel in courses - A) Copying sheets to an existing file and B) Exporting Two Sheet

excel in courses - A) Copying sheets to an existing file and B) Exporting Two Sheet

resolvedResolved · Low Priority · Version Standard

Michele has attended:
Excel VBA Intro Intermediate course
Access VBA course

A) Copying sheets to an existing file and B) Exporting Two Sheet

Hi,

I hope you will be able to help me. I am writing a collection of queries to:

i) Rename Worksheets in 2 workbooks (done)
ii) Copy worksheets from one file to the other (see query below)
iii) Sort sheets alphabetically (done)
iv) Separate out 2 sheets at a time and save as new workbook (see query below)

Please can you let me know how I can amend the following MACROs:

ii) - This MACRO needs to copy the worksheets from 3 to 15 into the workbook "T:\INFO\general\Adhocs\Michele\West Essex PCT\ Q2 Epping Locality PbC PBR Detail.xls" - this file already exists. The MACRO below falls over at "ActiveSheet.Move..." (if I remove this line, the sheets are copied to a new workbook):

Sub CopySheetsToDetailEpp()
'
Dim SheetName As String

Application.ScreenUpdating = False

Sheets("Summary WEPCT").Select

NoSheets = 15

For i = 3 To NoSheets

Sheets(i).Activate
Sheets(i).Copy
ActiveSheet.Move "T:\INFO\general\Adhocs\Michele\West Essex PCT\ Q2 Epping Locality PbC PBR Detail.xls"

Next i

Sheets("Summary WEPCT").Select

End Sub

iv) As I have already sorted my workbook, I need to copy the first and second sheets and save them as a new file, then the third and fourth and so on. The MACRO below only separates one sheet at a time, I have tried inserting (i)+1 a number of ways, but cannot seem to get the code right. Please see MACRO below:

Sub Export_Sheets()

Application.ScreenUpdating = False

Dim NoSheets As Integer
Dim i As Integer

CurrentMonth = InputBox("Enter Current Quarter for Report (e.g. Q2)")

NoSheets = 30

For i = 1 To NoSheets
Sheets.Select
Sheets(i).Activate
ActiveSheet.Copy
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("C1").Select
ActiveWorkbook.SaveAs Filename:="T:\INFO\general\Adhocs\Michele\West Essex PCT\PBR\" _
& "PBR Report for " & ActiveSheet.Name & " " & CurrentMonth & ".xls"
ActiveWorkbook.Close
Next i

Sheets("Summary WEPCT").Select

End Sub

I would be really grateful if you would be able to suggest ways of fixing these MACROs.

Many thanks in advance,
Michele

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Use the Format Painter to copy formatting more than once in Excel

The format painter tool provides a quick and easy way to copy formatting from one cell to another in Word.

The only problem is that if you click the Format Painter once to turn it on, you can only click and drag over a single cell or adjacent range of cells; then the Format Painter turns itself off automatically.

If you want to copy formatting to cells or groups of cells that are not adjacent to each other, double-click the Format Painter - this way you will be able to copy formatting to multiple cells.

When you have finished using Format Painter, press the Esc key or click on the Format Painter button once to turn it off.

View all Excel hints and tips


Server loaded in 0.07 secs.