View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Copy from two files

And even further, how do you know what worksheet to copy to?

If you want to prompt the user, you could...

Option Explicit
Sub testme()

Dim rngF As Range
Dim rngT As Range

Set rngF = Nothing
On Error Resume Next
Set rngF = Application.InputBox(Prompt:="Select the range", _
Default:=Selection.Areas(1).Address(external:=True ), _
Type:=8).Areas(1)
On Error GoTo 0

If rngF Is Nothing Then
MsgBox "Try later"
Exit Sub
End If

Set rngT = Nothing
On Error Resume Next
Set rngT = Application.InputBox(Prompt:="Select the range", Type:=8) _
.Cells(1)
On Error GoTo 0

If rngT Is Nothing Then
MsgBox "Try later"
Exit Sub
End If

rngF.Copy _
Destination:=rngT

Application.CutCopyMode = False

End Sub


You can swap between workbooks by clicking on Window and choosing the workbook
from there.


Annie wrote:

Is is possible for a macro to copy a range of cells from one file to the same
range in another file? The two files would be open; but the file names may
change. The recorder records absolute ranges correctly, but hard codes the
file names. Thanks for any help.
Annie


--

Dave Peterson