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