VBA - Copy data from one Workbook/Worksheet to another Workbook/Worksheet using Worksheet Name

PhilW_34

Board Regular
Joined
Jan 4, 2007
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hello,

Sorry I couldn't come up with a better title.

I have two files open. Right now I'm manually updating this year's file with data from last year's. I have code which selects the worksheet I'm viewing and copies information into the second workbook. It is semi-efficient.

Is it possible to look at the worksheet name in file A and search for it in File B. When/if found, then copy data from that worksheet onto the same named worksheet in file A? I would want this to loop for all worksheets in workbook A. I have the code for copying and pasting. I don't have any idea how to take the worksheet name from File A, search then select the worksheet from Worksheet B. I feel like I'm being clear as mud.

Any comments are welcome. Thank you for looking and giving my question some consideration.

Phil

Currently selecting each tab then running this code.

Code:
Sub Copy_Paste_BetweenFiles()

    Application.ScreenUpdating = False
    DisplayAlerts = False
    'Change file names as needed.
        Windows("File B.xlsm").Activate
            Range("A5:N10,A29:N29").Copy
        
        Windows("FileA.xlsm").Activate
        
        With Range("A4")
            .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            .PasteSpecial Paste:=xlPasteComments, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        End With
    
    Application.ScreenUpdating = True
    DisplayAlerts = True
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,215,741
Messages
6,126,592
Members
449,320
Latest member
Antonino90

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