copy a range from one workbook to another

luvbite38

Active Member
Joined
Jun 25, 2008
Messages
368
Hi guys,

I have two workbooks

1- FromCopy
2-ToCopy

They both have over 600 worksheets and both are identical in both books. I am tryin to run a macro which should copy a range (A2:A9) from each sheet of FromCopy and paste it in sheet with the similar name into ToCopy
Also, I want to run this macro on all the sheets except two (Intro and Lukups)

example

Select workbook FromCopy Select Sheet Called A Copy range A2:A9
Select workbook ToCopy Select Sheet called with same name i.e. A and paste the range into A2:A9
and repeat this procedure to all the sheets except two sheets (Intro and Lukups)

I hope it makes sense?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Something like this? (not the cleanest but best i can do im afraid)

Code:
Sub OpenEx()
    Dim sPath As String
    Dim copyto As Workbook
    Dim from As Workbook
    Dim ws As Worksheet
     
    sPath = "F:\Desktop\Copy From.xlsx"  'change the path to suit
    Set copyto = ThisWorkbook
    Set from = Workbooks.Open(sPath)
    Application.ScreenUpdating = False
     
    For Each ws In from.Worksheets
        
        ws.Select
        wsname = ws.Name
        If ws.Name <> "Intro" Then
        If ws.Name <> "Lukups" Then
        
        Range("A2:A9").Copy
        Windows("copy to").Activate
        Sheets(wsname).Select
        Range("A2").Select
        ActiveSheet.Paste
        Windows("Copy from").Activate
        
        End If
        End If
    Next
 Application.ScreenUpdating = True
End Sub
 
Upvote 0
Something like this? (not the cleanest but best i can do im afraid)

Code:
Sub OpenEx()
    Dim sPath As String
    Dim copyto As Workbook
    Dim from As Workbook
    Dim ws As Worksheet
     
    sPath = "F:\Desktop\Copy From.xlsx"  'change the path to suit
    Set copyto = ThisWorkbook
    Set from = Workbooks.Open(sPath)
    Application.ScreenUpdating = False
     
    For Each ws In from.Worksheets
        
        ws.Select
        wsname = ws.Name
        If ws.Name <> "Intro" Then
        If ws.Name <> "Lukups" Then
        
        Range("A2:A9").Copy
        Windows("copy to").Activate
        Sheets(wsname).Select
        Range("A2").Select
        ActiveSheet.Paste
        Windows("Copy from").Activate
        
        End If
        End If
    Next
 Application.ScreenUpdating = True
End Sub


Hey mate,

you're a gem

I had to make some minor adjustment but this worked like a charm.......

YOU'RE A SUPERSTAR

Regards,

LB
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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