Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Cut and Paste Macro.

So I'm having an inputbox pop-up so I can have the data from that sheet
cut and pasted into the new sheet. It all seems to work, but the paste
portion always errors out. Any ideas what I'm doing wrong?

Thanks!

Workbooks.Open Filename:=strFile
Selection.CurrentRegion.Select
Selection.Copy
ActiveWindow.Close
Worksheets("All Movements").Select
Range("A1").Select
ActiveSheet.Paste

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Cut and Paste Macro.

I Believe it's because you have closed the workbook with .DisplayAlerts
disabled, which tells excel to blow away the large amounts of information in
the clipboard. Try this order instead:
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ActiveWorkbook
Set wb2 = Workbooks.Open(strFile)
Selection.CurrentRegion.Copy wb1.Worksheets("All Movements").Range("A1")
wb2.Close
--
Charles Chickering

"A good example is twice the value of good advice."


" wrote:

So I'm having an inputbox pop-up so I can have the data from that sheet
cut and pasted into the new sheet. It all seems to work, but the paste
portion always errors out. Any ideas what I'm doing wrong?

Thanks!

Workbooks.Open Filename:=strFile
Selection.CurrentRegion.Select
Selection.Copy
ActiveWindow.Close
Worksheets("All Movements").Select
Range("A1").Select
ActiveSheet.Paste


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Cut and Paste Macro.


wrote:
I altered it to this:

Dim strFile As String

strFile = InputBox( _
prompt:="What is the path and name of the new Admin file?", _
Title:="Admin File Update", _
Default:="T:\General\John Bock\my documents\AdminFile.xls")

Workbooks.Open Filename:=strFile
Selection.CurrentRegion.Select
Selection.Copy
Worksheets("All Movements").Select
Range("A1").Select
Selection.PasteSpecial
-------------------------------------------------------

It doesn't error out, but it also doesn't work at all. It opens the new
file as asked, and copies it. However it does not paste the sheet into
the other workbook.

Any ideas?
Thanks.


I just glanced at your code the first time around and just told you how
not to get the error. The reason that nothing is happening is that when
you open a workbook in code it becomes the activeworkbook. So selection
would return the cell A1 of the file that you had just opened.Since you
copied and pasted in the same cell the same range it appears nothing
happened. Looking at it further I think that you are trying to copy the
current region to the "All Movements" sheet or you might want to copy
the entire worksheet contents to it. Here is code that I wrote to
accomplish a similar task.

Dim cpyrg As Range
Dim pstrg As Range
Dim rg1 As Range
Dim wbknm As String
Dim shtnm As String
Dim rgadd As String

wbknm = ActiveWorkbook.Name
shtnm = ActiveSheet.Name
rgadd = ActiveSheet.UsedRange.Address

' these statements recall the original details of the range I would
like to copy.
' The UsedRange finds the entire range that has any info on a sheet.
' You can replace it with Activecell.CurrentRegion if that is what
you need

Workbooks.Open Filename:="C:\Documents and Settings\acctemp2\My
Documents\clrstest.xls"

Set cpyrg = Workbooks(wbknm).Worksheets(shtnm).Range(rgadd)
' This copies the range that I want to the clipboard.
' I could have declared it directly above the Workbooks.Open
Statement.
' Set cpyrg = ActiveWorkbook.ActiveSheet.ActiveSheet.UsedRange
' This would negate the need for all the string variables. I have
used both
' methods it depends on what you are doing.
cpyrg.Copy

Set pstrg = ActiveSheet.Range("a1")
pstrg.PasteSpecial
' If you are copying to a master spreadsheet you may want the
original values to remain.
' To insert the copied range replace the pstrg.PasteSpecial statement
with
' pstrg.Insert Shift:=xldoiwn

I hope this helps. A little narrative about what you are trying to do
often helps in answering questions.

HTH

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
copy multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Excel Programming 1 October 17th 05 08:56 AM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM
Cut and Paste using Macro gives paste special method error Lourens Pentz Excel Programming 3 November 21st 04 10:42 PM
Macro to Paste to specific line, and continue to Paste each time on next row not over tomkarakowski[_2_] Excel Programming 1 May 28th 04 06:50 PM
Macro to Copy/Paste then Paste to Next Line tomkarakowski Excel Programming 1 May 28th 04 01:19 AM


All times are GMT +1. The time now is 02:47 AM.

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

About Us

"It's about Microsoft Excel"