ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autocopy between 2 workbooks (https://www.excelbanter.com/excel-programming/335779-autocopy-between-2-workbooks.html)

FrigidDigit

Autocopy between 2 workbooks
 
Hi all,

I would like to create code to accomplish the following but as I know very
little any help would be appreciated:

I have 2 workbooks of which the names could differ from time to time
I would like to create a procedure to copy say range A1:H13 from workbook 1
to the same range in workbook 2.
Which commands would I use to switch between the 2 workbooks and how will I
identify them so that I paste to the correct 1?

TIA

FD




Dave Peterson

Autocopy between 2 workbooks
 
Saved from a previous post:

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.

If you always want to paste into the same address, you could change this line:

rngF.Copy _
Destination:=rngT

to

rngF.Copy _
Destination:=rngT.parent.range(rngf.address)

But you'd still need some way to get that other worksheet.


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

FrigidDigit wrote:

Hi all,

I would like to create code to accomplish the following but as I know very
little any help would be appreciated:

I have 2 workbooks of which the names could differ from time to time
I would like to create a procedure to copy say range A1:H13 from workbook 1
to the same range in workbook 2.
Which commands would I use to switch between the 2 workbooks and how will I
identify them so that I paste to the correct 1?

TIA

FD


--

Dave Peterson

FrigidDigit

Autocopy between 2 workbooks
 
Dave thank you SO MUCH man!
Appreciate the help.


"Dave Peterson" wrote in message
...
Saved from a previous post:

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.

If you always want to paste into the same address, you could change this
line:

rngF.Copy _
Destination:=rngT

to

rngF.Copy _
Destination:=rngT.parent.range(rngf.address)

But you'd still need some way to get that other worksheet.


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

FrigidDigit wrote:

Hi all,

I would like to create code to accomplish the following but as I know
very
little any help would be appreciated:

I have 2 workbooks of which the names could differ from time to time
I would like to create a procedure to copy say range A1:H13 from workbook
1
to the same range in workbook 2.
Which commands would I use to switch between the 2 workbooks and how will
I
identify them so that I paste to the correct 1?

TIA

FD


--

Dave Peterson





All times are GMT +1. The time now is 01:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com