Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

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

ResolvedVersion 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:

Checking if a calculation adheres to Order of Precedence

When writing formulas you must make sure that results will be calculated as you intended.

Excel adheres to the standard order of precedence for calculations. It calculates percentages, exponents, multiplication, and division in this order before calculating addition and subtraction.

For example, =7+5*3 results in an answer of 22, not 36.

To force a calculation to be completed before another calculations, place the section in parentheses: =(7+5)*3 will result in 36.

To check how excel is evaluating a formula, click on the cell and select the 'Tools' menu, select 'Formula Auditing' and click 'Evaluate Formula'

In the dialog box click on 'Evaluate' to watch as each part of the formula is successively calculated.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.