copy from one open excel doc to another

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,742
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,305
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
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,742
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Thanks Mumps,
this has been exactly what i needed :)
Tony
 

Watch MrExcel Video

Forum statistics

Threads
1,129,580
Messages
5,637,211
Members
416,961
Latest member
sigrid6940

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
Top