Search for a tab in a Master workbook from another workbook, if it exists then skip it and if not, create or replace.

ima2015

New Member
Joined
Sep 19, 2023
Messages
4
I have a Master.xlsm workbook, and some excels files (File 1.xlsm, File 2.xlsm) from which I would like to transfer their data into the master workbook. The job here is two folds:

1- Search for the tab from File 1 in the Master and if it exists, then skip it, if not then replace tab that do not belong in File 1 and File 2 (Note that File 1 and File 2 have the same tabs).
In the Master workbook, I do not want to touch tabs "Assets A", and "Assets B". Master.xlsm changes periodically based on File 1 and File 2.
2-Transfer the data (F1_Price, F2_Price) from the tabs from File 1, File 2 into the Master workbook.

I started putting together a code to do the job, but I am unable to finish it. Any help is appreciated.

I am not sure why I was not able to upload macro files, so i dropped screen shots. Hope that helps.

Thanks

1695145606505.png


1695145672438.png
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Sorry, below is the partial code started:

Sub CreateSheet()
Dim rs As Worksheet
Dim wsFile As Worksheet
Dim wbMaster As Workbook

On Error GoTo clear_err

'Open File 1 from source 1
Workbooks.Open ("C:\Users\mougu\Documents\Test\File 1.xlsm")

Set wsFile = Workbooks("File1.xlsm").Worksheets
Set wbMaster = Workbooks("C:\Users\mougu\Documents\Test\Master.xlsm")

wbMaster.Activate

For Each rs In wbMaster.Worksheets
If rs.Name <> "Assets A" And rs.Name <> "Assets B" Then rs.Name = wbFile.Worksheets.Value

Next rs

clear_err:
MsgBox Err.Description

Workbooks("File 1.xlsm").Close


End Sub
 
Upvote 0
VBA Code:
Sub CreateSheet()
    Dim rs As Worksheet
    Dim wsFile As Worksheet
    Dim wbMaster As Workbook
    
On Error GoTo clear_err

    'Open File 1 from source 1
    Workbooks.Open ("C:\Users\m\Documents\Test\File 1.xlsm")
    
    Set wsFile = Workbooks("File1.xlsm").Worksheets
    Set wbMaster = Workbooks("C:\Users\m\Documents\Test\Master.xlsm")
    
    wbMaster.Activate
    
    For Each rs In wbMaster.Worksheets
    If rs.Name <> "Assets A" And rs.Name <> "Assets B" Then rs.Name = wbFile.Worksheets.Value
    
Next rs

clear_err:
MsgBox Err.Description
    
    Workbooks("File 1.xlsm").Close

       
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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