copy from one open excel doc to another

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
hi everyone,
i need a macro that can copy data into the active excel document from the other open document.

So I have the document the macro is saved in and it has a sheet called raw data that is empty,
I want the macro to check that there are only two excel documents of any type open xlsm xls xlsx (but some people might have the personal workbook as well so somehow take this into account)
if more than two are open just message box "too many documents open" exit sub
if there are only two copy from the other open documents active sheet all contents which should be Columns A toV
and paste values into thisworkbook sheet "raw data"

please help if you can

Thanks

Tony
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:
VBA Code:
Sub CopyData()
    If Application.Workbooks.Count > 2 Then
        MsgBox ("Too many documents open.")
        Exit Sub
    End If
    Application.ScreenUpdating = False
    Dim WB As Workbook
    For Each WB In Workbooks
        If WB.Name <> ThisWorkbook.Name Then
            WB.ActiveSheet.UsedRange.Copy Sheets("raw data").Cells(1, 1)
        End If
    Next WB
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,993
Members
448,539
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top