Macro to compare worksheet names in 2 workbooks

wilkisa

Well-known Member
Joined
Apr 7, 2002
Messages
657
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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