Macro to compare worksheet names in 2 workbooks

wilkisa

Well-known Member
Joined
Apr 7, 2002
Messages
654
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
I have 2 workbooks each with 30 sheets, numbered 1 to 30. I need to link data from Workbook1 Sheet1 to the data in Workbook2 Sheet1, Workbook1 Sheet2 to Workbook2 Sheet2, etc. etc. etc. Can someone help me with this code?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
something like this?

Code:
Sub coord()

    Dim wb As Workbook
    Dim sht As Worksheet
    Dim sht2 As Worksheet
    Dim rnge As Range
    
    
    'assuming that the source workbook is currently open
    
    Set wb = Workbooks("book1")
    
    For Each sht In wb.Sheets
    
        On Error Resume Next
        
        Set sht2 = ActiveWorkbook.Sheets(sht.Name)
        
        On Error GoTo 0
        
        If Not sht2 Is Nothing Then
    
            For Each rnge In sht.UsedRange
            
                If sht2.Range(rnge.Address).Value = "" And rnge.Value <> "" Then
                
                    sht2.Range(rnge.Address).Formula = "='[" & wb.Name & "]" & sht.Name & "'!" & rnge.Address
                    
                End If
            
            Next rnge
        
            Set sht2 = Nothing
            
        End If
        
    Next sht
    
    Set wb = Nothing

End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,836
Messages
5,855,912
Members
431,774
Latest member
WillWilco

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