Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim M As Long, i As Long, iOrig As Long, j As Long
Dim rngOrig As Range
Dim arrOrig As Variant, arrOut As Variant
Dim dictOrig As Object, dictKey As String
Application.ScreenUpdating = False
Set rngOrig = Me.Range("A1").CurrentRegion
arrOrig = rngOrig.Value
Set dictOrig = CreateObject("Scripting.dictionary")
dictOrig.CompareMode = vbTextCompare
' Load original index into Dictionary
For i = 1 To UBound(arrOrig)
dictKey = arrOrig(i, 1)
If Not dictOrig.exists(dictKey) Then
dictOrig(dictKey) = i
End If
Next i
M = 1
With Me
.Columns(1).ClearContents
.Cells(1, 1) = "INDEX"
.Cells(1, 1).Name = "Index"
End With
ReDim arrOut(1 To ThisWorkbook.Worksheets.Count, 1 To UBound(arrOrig, 2) - 1) ' Drop Column A
For Each wSheet In Worksheets
If wSheet.Name <> Me.Name Then
M = M + 1
With wSheet
.Range("M1").Name = "Start" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("M1"), Address:="", SubAddress:="Index", TextToDisplay:="Back to Index"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(M, 1), Address:="", SubAddress:="Start" & wSheet.Index, TextToDisplay:=wSheet.Name
dictKey = wSheet.Name
If dictOrig.exists(dictKey) Then
iOrig = dictOrig(dictKey)
For j = 1 To UBound(arrOut, 2)
arrOut(M - 1, j) = arrOrig(iOrig, j + 1)
Next j
End If
End If
Next wSheet
Me.Range("B2").Resize(M - 1, UBound(arrOut, 2)).Value = arrOut
Application.ScreenUpdating = True
End Sub