I almost solved the problem...the script below categorizes the LAP, LHP, LWPs into their proper columns. The only problem I have now is that I can't figure out how to put everything else into a miscellaneous column. Probably not the prettiest code...or most logical but it works haha.
Private Sub Worksheet_Activate()
'Declare Vairables
Dim wSheet As Worksheet
Dim x, y, z As Long
x = 2
y = 2
z = 2
With Me
'Clears previous index
.Range("A:D").ClearContents
'Formatting of cells
.Range("A1:D2").Font.Bold = True
.Range("A1:D2").Font.Underline = False
.Range("A1:D2").Font.Color = 1
'Labelling of first two rows
.Cells(1, 1) = "INDEX"
.Cells(2, 1) = "LAP"
.Cells(2, 2) = "LHP"
.Cells(2, 3) = "LWP"
.Cells(2, 4) = "Misc"
.Cells(1, 1).Name = "Index"
End With
'To find each worksheet with LAP and create a hyperlink into column A
For Each wSheet In Worksheets
If wSheet.Name <> Me.Name And InStr(wSheet.Name, "LAP") Then
x = x + 1
With wSheet
.Range("A1").Name = "Start_" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Chemical Name"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(x, 1), Address:="", _
SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
End If
Next wSheet
'To find each worksheet with LHP and create a hyperlink into column B
For Each wSheet In Worksheets
If wSheet.Name <> Me.Name And InStr(wSheet.Name, "LHP") Then
y = y + 1
With wSheet
.Range("A1").Name = "Start_" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Chemical Name"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(y, 2), Address:="", _
SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
End If
Next wSheet
'To find each worksheet with LWP and create a hyperlink into column C
For Each wSheet In Worksheets
If wSheet.Name <> Me.Name And InStr(wSheet.Name, "LWP") Then
z = z + 1
With wSheet
.Range("A1").Name = "Start_" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Chemical Name"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(z, 3), Address:="", _
SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
End If
Next wSheet
End Sub
Bookmarks