Gingertrees
Well-known Member
- Joined
- Sep 21, 2009
- Messages
- 697
New riddle with my copy-worksheet routine:
I'm copying in a daily report from a separate workbook into my processing workbook. My brain thinks that this should put it at the end, after all the other sheets. However, this isn't happening. Why?
I'm copying in a daily report from a separate workbook into my processing workbook. My brain thinks that this should put it at the end, after all the other sheets. However, this isn't happening. Why?
Code:
Sub OpenCopyApple ()
Dim tempfiletocopy As Variant
Dim tempfileName As String
Dim sheet As Worksheet
tempfiletocopy = Application.GetOpenFilename
Workbooks.Open tempfiletocopy
tempfileName = ActiveWorkbook.Name
Sheets("Sheet1").Copy After:=Workbooks("ORANGEA.xlsm").Sheets(Sheets.Count)
If Not SheetExists("apple" & Sheets.Count) Then
ActiveSheet.Name = "apple" & Sheets.Count
Else
ActiveSheet.Name = "apple" & (Sheets.Count * 3)
End If
End Sub
Function SheetExists(shName As String) As Boolean
SheetExists = False
For Each sh In ActiveWorkbook.Sheets
If sh.Name = shName Then
SheetExists = True
Exit For
End If
Next sh
End Function