Macro to copy data from the other open xmls document to this one?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

Hi you can help me.
I have a document my boss uses all day everyday and he keeps asking me to add new deshboards etc.
The thing is it takes me a while to do this which mean this document is out of service.
However because of the way its set up I could copy data from his version to the new version and this would work.
but i don't know what the names of the two documents are going to be?
to make it easier there will only ever be two two excel documents open.
So what i need is this.

A macro that when run,
Goes to the only other open workbook.
goes to sheet "Raw Data1"
Copy's Range B2:Y & Lastrow

Goes to the workbook the macro is stored in and pastes it into sheet "Raw Data2" A2 (I'm using Raw Data2 as a test sheet I'll change it to Raw Data1 once I know it works.)

I'm having difficulty because I don't know what the other workbook name is so any help would be greatly appreciated.

Thanks

Tony
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try:
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim WB As Workbook, srcWS As Worksheet, desWS As Worksheet
    Set desWS = ThisWorkbook.Sheets("Raw Data2")
    For Each WB In Application.Workbooks
        If WB.Name <> ThisWorkbook.Name Then
            Set srcWS = WB.Sheets("Raw Data1")
            With srcWS
                .Range("B2", .Range("Y" & .Rows.Count).End(xlUp)).Copy desWS.Range("A2")
            End With
        End If
    Next WB
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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