PC Review


Reply
Thread Tools Rate Thread

Copy worksheet from one workbook to another workbook

 
 
David Ryan
Guest
Posts: n/a
 
      29th Dec 2009
Hi Guys hope someone can take the time to help

I have a workbook with a sheet called "hscount" I would like to copy the
values of this sheet to another workbook called "hscounttotals" with the
sheet name based on the current day, month & year, eg "01december2009" the
next month "15january2010" and so on.

I want to attached this to a button the user clicks to do the copy.

Note I only want to copy the values each time.
Regards
David
 
Reply With Quote
 
 
 
 
David Ryan
Guest
Posts: n/a
 
      29th Dec 2009
Hi Joel thanks for that. i think it is almost there.

when run the open file "box" opens when you select the file to open the
following error message appears.

Run time error '1004'
Application-defined or object-defined error.
When you click debug the following is highlighted in your code

NewSht.PasteSpecial _
Paste:=xlPasteValues

Hope you can assist further.

Regards David
--
Regards
David


"joel" wrote:

>
> Try this code. I used GetOpenfilename to open the workbook. I also
> copies both the Values and the formats (not the formulas).
>
>
> Sub MakeNewTotals()
>
> Set Mytemplate = ThisWorkbook.Sheets("hscount")
>
> fileToOpen = Application _
> .GetOpenFilename("Excel Files (*.xls), *.xls")
> If fileToOpen = False Then
> MsgBox ("Cannot Open file - Exiting Macro")
> Exit Sub
> End If
>
> Set bk = Workbooks.Open(Filename:="fileToOpen")
>
> With bk
> 'Create Data for sheet like this "01december2009"
> DateStr = Format(Date, "ddmmmmyyyy")
>
> 'make new worksheet
> Set NewSht = .Sheets.Add(after:=.Sheets(.Sheets.Count))
> NewSht.Name = DateStr
>
> Mytemplate.Cells.Copy
> 'paste values
> NewSht.PasteSpecial _
> Paste:=xlPasteValues
>
> 'paste formats
> NewSht.PasteSpecial _
> Paste:=xlPasteFormats
>
> 'save results
> .save
> End With
>
>
> End Sub
>
>
> --
> joel
> ------------------------------------------------------------------------
> joel's Profile: 229
> View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165571
>
> Microsoft Office Help
>
> .
>

 
Reply With Quote
 
David Ryan
Guest
Posts: n/a
 
      30th Dec 2009
Hi Joel worked a treat!! Thanks
--
Regards
David


"joel" wrote:

>
> I left out cells
>
> from
>
> 'paste values
> NewSht.PasteSpecial _
> Paste:=xlPasteValues
>
> 'paste formats
> NewSht.PasteSpecial _
> Paste:=xlPasteFormats
>
>
> to
>
> 'paste values
> NewSht.cells.PasteSpecial _
> Paste:=xlPasteValues
>
> 'paste formats
> NewSht.cells.PasteSpecial _
> Paste:=xlPasteFormats
>
>
> --
> joel
> ------------------------------------------------------------------------
> joel's Profile: 229
> View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165571
>
> Microsoft Office Help
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy worksheet from one workbook to a master workbook mvannatta Microsoft Excel Worksheet Functions 2 15th Apr 2009 08:32 PM
Re: Copy worksheet from one workbook to a master workbook Ron de Bruin Microsoft Excel Worksheet Functions 0 15th Apr 2009 07:57 PM
Copy Excel Worksheet to new Workbook via VBA without Links to original Workbook JamesDMB Microsoft Access Form Coding 0 21st Mar 2007 06:13 PM
Copy Data from Workbook into specific Worksheet in other Workbook? kingdt Microsoft Excel Misc 1 16th Mar 2006 06:55 PM
copy worksheet from closed workbook to active workbook using vba =?Utf-8?B?bWFuZ28=?= Microsoft Excel Worksheet Functions 6 9th Dec 2004 07:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:07 PM.