PDA

View Full Version : [SOLVED:] Table Of Contents - Help required to customize the code



anish.ms
11-07-2020, 08:22 AM
Hi, I'm a newbie in VBA.
I request your help in the attached code downloaded from the internet (workbook attached). The code creates a new sheet in front of all the sheets with a list of sheets with hyperlink. I need help in the following-
(1) Adding the values also from cell A1 in all the sheets against the sheet name. (Highlighted in yellow).
(2) And a link back to the Contents (TOC) sheet in all other sheets in cell N1
Thanks in advance

Paul_Hossler
11-07-2020, 10:16 AM
In attached





'----------------------------------------------------
Application.EnableEvents = False
.Cells(x + 2, 4).Value = sht.Range("A1").Value
On Error Resume Next
sht.Range("N1").Hyperlinks.Delete
On Error GoTo 0
sht.Range("N1").ClearContents
sht.Range("N1").Hyperlinks.Add Anchor:=sht.Range("N1"), Address:="", SubAddress:="Contents!A1", TextToDisplay:="Go To TOC"
Application.EnableEvents = True
'----------------------------------------------------

anish.ms
11-07-2020, 11:02 AM
Thanks again for the continued support

SamT
11-08-2020, 11:56 AM
Lists all sheets. Sorts Listing alphabetically. Activates selected sheet. Always stay next to active sheet.

Copy TOC sheet to any workbook. Use Rows 1 to 3 for notes/info/instructions

anish.ms
11-27-2020, 12:09 PM
This is awesome Mr. Sam

anish.ms
11-28-2020, 04:59 AM
Lists all sheets. Sorts Listing alphabetically. Activates selected sheet. Always stay next to active sheet.

Copy TOC sheet to any workbook. Use Rows 1 to 3 for notes/info/instructions

Hi,
I have made few modifications in the code as per my requirement. Request your help in the following areas where my knowledge is limited as a beginner to VBA.
(1) I have added serial number before the sheet names. But my code is skipping 1 number where the TOC sheet is moving

TOC.Cells(r, 2).Value = i
(2) Can i move to the sheet even if i click on column D

Private Sub Worksheet_SelectionChange(ByVal Target As Range) Application.ScreenUpdating = False


''''Check criteria for running this sub
'Is only one Cell selected
If Target.Count <> 1 Then Exit Sub
'Is there a List
If LastRow < 3 Then Exit Sub
'Is the selection in the List
If Intersect(Target, Range("C3:C" & CStr(LastRow))) Is Nothing Then Exit Sub

''''Move the Index Sheet, Activate the chosen Sheet, and Select "A1" _
on the chosen Sheet.
TOC.Move Before:=Sheets(Target.Value)
Sheets(Target.Value).Activate
ActiveSheet.Range("A1").Select

Application.ScreenUpdating = True
End Sub

Thanks in advance
Unable to attach the file

Paul_Hossler
11-28-2020, 09:28 AM
I had done it a little differently.

I used an add in to insert a TOC worksheet into the active workbook. It doesn't refresh when activated like SamT's (although it could)

That way I didn't have to worry about copying a TOC worksheet into every workbook

On the QAT i just added a call to the add in

27510

anish.ms
11-28-2020, 10:31 AM
Dear Paul, thanks for your response
I have added the code I shared initially with your suggested codes in my personal.xlsb workbook to call it in other workbooks when required.
I found SamT's code for TOC sheet to move along with interesting and thought of using it in one of the workbook.