Programmatically creating hyperlinks
I have one worksheet that lists a bunch of titles. Then for each title in the
first worksheet, I have another worksheet that corresponds to one of those titles on the first worksheet. I could have up to 250 worksheets, one for each title in the first worksheet. Can someone provide me with a way to programmatically make the titles on the first sheet become hyperlinks that point to its corresponding sheet in the workbook. Plus, this is a dynamically workbook. Each week, it will have different titles and corresponding worksheets for each, so I need to be able to save this code for use each week when I create this workbook. I've tried working on it myself, but am getting stuck on how to get to the correct sheet for each title. My attempt is below if anyone needs a good laugh :) Any help will be greatly appreciated. Code:
Sub LinkSheets() |
Programmatically creating hyperlinks
Assuming your titles are in one column (column A beginning at row 1) and
there are no empty rows between titles: For Each cell In Range("A1:A" & Range("A65536").End(xlUp).Row) cell.Hyperlinks.Add Anchor:=Range("A" & cell.Row), Address:="", SubAddress:= _ "'" & Sheets(cell.Value).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Name Next cell HTH, Paul -- "Wannabe" wrote in message ... I have one worksheet that lists a bunch of titles. Then for each title in the first worksheet, I have another worksheet that corresponds to one of those titles on the first worksheet. I could have up to 250 worksheets, one for each title in the first worksheet. Can someone provide me with a way to programmatically make the titles on the first sheet become hyperlinks that point to its corresponding sheet in the workbook. Plus, this is a dynamically workbook. Each week, it will have different titles and corresponding worksheets for each, so I need to be able to save this code for use each week when I create this workbook. I've tried working on it myself, but am getting stuck on how to get to the correct sheet for each title. My attempt is below if anyone needs a good laugh :) Any help will be greatly appreciated. Code:
Sub LinkSheets() |
Programmatically creating hyperlinks
Thank you for that piece, but I also need to be able to go to the page the
hyperlink is referencing and place a hyperlink back to the calling (first) page. Thanks. "PCLIVE" wrote: Assuming your titles are in one column (column A beginning at row 1) and there are no empty rows between titles: For Each cell In Range("A1:A" & Range("A65536").End(xlUp).Row) cell.Hyperlinks.Add Anchor:=Range("A" & cell.Row), Address:="", SubAddress:= _ "'" & Sheets(cell.Value).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Name Next cell HTH, Paul -- "Wannabe" wrote in message ... I have one worksheet that lists a bunch of titles. Then for each title in the first worksheet, I have another worksheet that corresponds to one of those titles on the first worksheet. I could have up to 250 worksheets, one for each title in the first worksheet. Can someone provide me with a way to programmatically make the titles on the first sheet become hyperlinks that point to its corresponding sheet in the workbook. Plus, this is a dynamically workbook. Each week, it will have different titles and corresponding worksheets for each, so I need to be able to save this code for use each week when I create this workbook. I've tried working on it myself, but am getting stuck on how to get to the correct sheet for each title. My attempt is below if anyone needs a good laugh :) Any help will be greatly appreciated. Code:
Sub LinkSheets() |
Programmatically creating hyperlinks
For Each cell In Range("A1:A" & Range("A65536").End(xlUp).Row)
cell.Hyperlinks.Add Anchor:=Range("A" & cell.Row), Address:="", SubAddress:= _ "'" & Sheets(cell.Value).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Name 'This line will create a hyperlink in cell A1 that links back to the original page. It uses the value that is in A1. If you want to use a different cell, then modify as needed. Sheets(cell.Value).Range("A1").Hyperlinks.Add Anchor:=Sheets(cell.Value).Range("A1"), Address:="", SubAddress:= _ "'" & Sheets(1).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Range("A1").Valu e Next cell HTH, Paul -- "Wannabe" wrote in message ... Thank you for that piece, but I also need to be able to go to the page the hyperlink is referencing and place a hyperlink back to the calling (first) page. Thanks. "PCLIVE" wrote: Assuming your titles are in one column (column A beginning at row 1) and there are no empty rows between titles: For Each cell In Range("A1:A" & Range("A65536").End(xlUp).Row) cell.Hyperlinks.Add Anchor:=Range("A" & cell.Row), Address:="", SubAddress:= _ "'" & Sheets(cell.Value).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Name Next cell HTH, Paul -- "Wannabe" wrote in message ... I have one worksheet that lists a bunch of titles. Then for each title in the first worksheet, I have another worksheet that corresponds to one of those titles on the first worksheet. I could have up to 250 worksheets, one for each title in the first worksheet. Can someone provide me with a way to programmatically make the titles on the first sheet become hyperlinks that point to its corresponding sheet in the workbook. Plus, this is a dynamically workbook. Each week, it will have different titles and corresponding worksheets for each, so I need to be able to save this code for use each week when I create this workbook. I've tried working on it myself, but am getting stuck on how to get to the correct sheet for each title. My attempt is below if anyone needs a good laugh :) Any help will be greatly appreciated. Code:
Sub LinkSheets() |
Programmatically creating hyperlinks
That is pretty close to what I want. Thank you very much. I believe I can
take it from here. "PCLIVE" wrote: For Each cell In Range("A1:A" & Range("A65536").End(xlUp).Row) cell.Hyperlinks.Add Anchor:=Range("A" & cell.Row), Address:="", SubAddress:= _ "'" & Sheets(cell.Value).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Name 'This line will create a hyperlink in cell A1 that links back to the original page. It uses the value that is in A1. If you want to use a different cell, then modify as needed. Sheets(cell.Value).Range("A1").Hyperlinks.Add Anchor:=Sheets(cell.Value).Range("A1"), Address:="", SubAddress:= _ "'" & Sheets(1).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Range("A1").Valu e Next cell HTH, Paul -- "Wannabe" wrote in message ... Thank you for that piece, but I also need to be able to go to the page the hyperlink is referencing and place a hyperlink back to the calling (first) page. Thanks. "PCLIVE" wrote: Assuming your titles are in one column (column A beginning at row 1) and there are no empty rows between titles: For Each cell In Range("A1:A" & Range("A65536").End(xlUp).Row) cell.Hyperlinks.Add Anchor:=Range("A" & cell.Row), Address:="", SubAddress:= _ "'" & Sheets(cell.Value).Name & "'!A1", TextToDisplay:=Sheets(cell.Value).Name Next cell HTH, Paul -- "Wannabe" wrote in message ... I have one worksheet that lists a bunch of titles. Then for each title in the first worksheet, I have another worksheet that corresponds to one of those titles on the first worksheet. I could have up to 250 worksheets, one for each title in the first worksheet. Can someone provide me with a way to programmatically make the titles on the first sheet become hyperlinks that point to its corresponding sheet in the workbook. Plus, this is a dynamically workbook. Each week, it will have different titles and corresponding worksheets for each, so I need to be able to save this code for use each week when I create this workbook. I've tried working on it myself, but am getting stuck on how to get to the correct sheet for each title. My attempt is below if anyone needs a good laugh :) Any help will be greatly appreciated. Code:
Sub LinkSheets() |
All times are GMT +1. The time now is 01:01 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com