Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default move worksheet to end of another workbook

Hi,
I'm using Excel 2010 and have two spreadsheets that I want to merge.
One of these is my timesheet workbook (called "breakdown 2013.xlsx") and the other is my daily time.
I have managed to create a macro that will mostly do what I want, but I cannot find the code to get the daily sheet to insert at the end of the "breakdown" without having to constantly change the number of sheets.

The code I'm using is :

ActiveSheet.Select
ActiveSheet.Move after:=Workbooks("breakdown 2013.xlsx").Sheets(135)

Can anyone assist with this - it's irking me no end.
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default move worksheet to end of another workbook

I tried your formula, but it didn't insert at the end of the workbook.
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default move worksheet to end of another workbook

It inserts it at the 2nd worksheet.

I do have other code before this bit (not that that should make a difference?)

Cells.Select
Selection.Columns.AutoFit
Columns("B:C").Select
Selection.NumberFormat = "[$-F400]h:mm:ss AM/PM"
Selection.ColumnWidth = 13.86
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Range("A18").Select

Cells.Select
Selection.Replace What:="*DAY", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

ActiveSheet.Select
ActiveSheet.Move after:=Workbooks("breakdown 2013.xlsx").Sheets(Sheets.Count)

Is this causing a problem - have I left something out, or put too much in ? Should this be a separate code ?


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,045
Default move worksheet to end of another workbook

On Wed, 7 Aug 2013 21:57:19 -0700 (PDT), wrote:

It inserts it at the 2nd worksheet.

I do have other code before this bit (not that that should make a difference?)

Cells.Select
Selection.Columns.AutoFit
Columns("B:C").Select
Selection.NumberFormat = "[$-F400]h:mm:ss AM/PM"
Selection.ColumnWidth = 13.86
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Range("A18").Select

Cells.Select
Selection.Replace What:="*DAY", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

ActiveSheet.Select
ActiveSheet.Move after:=Workbooks("breakdown 2013.xlsx").Sheets(Sheets.Count)

Is this causing a problem - have I left something out, or put too much in ? Should this be a separate code ?


OK, I see the problem. The Move line is looking at the wrong workbook to get the sheet count (my error).

Try this instead:

===================
With Workbooks("breakdown 2013.xlsx")
ActiveSheet.Move after:=.Sheets(.Sheets.Count)
End With
=============================

And, in your code above, there should be no need for any of your .Select statements

The following code should work just as well, and is less "cluttered", probably easier to follow and probably more efficient:

==========================================
Option Explicit
Sub foo()
With Cells
.Columns.AutoFit
With .Columns("B:C")
.NumberFormat = "[$-F400]h:mm:ss AM/PM"
.ColumnWidth = 13.86
End With
.Columns("D:D").Delete Shift:=xlToLeft
.Columns("D:D").Delete Shift:=xlToLeft
.Columns("E:E").Delete Shift:=xlToLeft
.Replace What:="*DAY", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With

With Workbooks("breakdown 2013.xlsx")
ActiveSheet.Move after:=.Sheets(.Sheets.Count)
End With
End Sub
====================================

And, since you have multiple workbooks open, you might want to ensure that this code only runs on the workbook/worksheet you want. By specifying ActiveSheet (and your original Cells.Select statement, as well as my With Cells line, both implicitly refer to ActiveSheet), it'll run on whatever workbook you have selected at the time.

Hard to tell what would work properly; as a minimum, something like:

if activeworkbook.Name < "daily_time" 'or whatever your base sheet is named
code lines
....
....
else
msgbox("Wrong workbook selected")
exit sub
end if
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default move worksheet to end of another workbook

Oh sweet !!
That works now - thank you soooo much.
I'm not terribly proficient with VBA, but can "get by" or resort to asking my husband - although he couldn't help with this one.
The code was originally created by my creating a macro and then "going thru the motions". That's prob'ly why it's so convoluted ?
Now it works brilliantly.
Again, thank you so much.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
move a worksheet from one workbook to another Wizard475 Excel Discussion (Misc queries) 1 February 13th 09 07:50 PM
Move to a named worksheet from any worksheet in the same workbook tango Excel Programming 2 December 10th 08 12:43 AM
Why can't you just Move a worksheet in Excel '07 to new workbook? Rania Excel Worksheet Functions 1 November 15th 07 08:51 PM
Move worksheet within workbook Dale Fye Excel Programming 2 February 1st 06 02:35 AM
MOVE Worksheet to another workbook ? MAS Excel Programming 6 July 3rd 05 10:37 PM


All times are GMT +1. The time now is 10:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"