Creating hyperlinks by macro

Hudco

Board Regular
Joined
Jan 4, 2006
Messages
131
Office Version
  1. 365
Hi good folk,
I have the following macro which works until the third last line. Apologies for pasting this here but I have not mastered this area very well. So this macro creates a list of the sheets which are numbered, lists the name that is in cell F1 on all sheets and the instruction which is coming to grief is supposed to get the amount calculated at F22 on all sheets and list it next to the previous two listings.

There is more code after this but it is just closing and locking the sheet.

Can anyone help. Thank you


Private Sub CommandButton1_Click()
ActiveWorkbook.Unprotect ("password")
Sheets("Rec").Select
ActiveSheet.Unprotect ("password")
Range("A5:I104").Select
Selection.ClearContents
Range("A5").Select
Dim aCell As Range
Dim ws As Worksheet
Set aCell = ThisWorkbook.Worksheets("Rec").Range("A5")
For Each ws In ThisWorkbook.Worksheets
If ws.Name > Worksheets("Rec").Range("S2") And ws.Name < Worksheets("Rec").Range("T2") Then
aCell.Value = ws.Name
aCell.Hyperlinks.Add Anchor:=aCell, Address:="", SubAddress:=ws.Name & "!A1"
Set aCell = aCell.Offset(1, 0)
End If
Next ws
Range("B5").Select
Dim bCell As Range
Dim wt As Worksheet
Set bCell = ThisWorkbook.Worksheets("Rec").Range("B5")
For Each wt In ThisWorkbook.Worksheets
If wt.Name > Worksheets("Rec").Range("S2") And wt.Name < Worksheets("Rec").Range("T2") Then
bCell.Value = Range("F1").Value
bCell.Hyperlinks.Add Anchor:=bCell, Address:="", SubAddress:=wt.Name & "!F1", TextToDisplay:=wt.Range("F1").Value
Set bCell = bCell.Offset(1, 0)
End If
Next wt
Sheets("Rec").Select
Range("C5").Select
Dim gCell As Range
Dim wa As Worksheet
Set gCell = ThisWorkbook.Worksheets("Rec").Range("C5")
For Each wa In ThisWorkbook.Worksheets
If wa.Name > Worksheets("Rec").Range("S2") And wa.Name < Worksheets("Rec").Range("T2") Then
gCell.Value = Range("F22").Value
gCell.Hyperlinks.Add Anchor:=gCell, Address:="", SubAddress:=wa.Name & "!F22", TextToDisplay:=wa.Range("F22").Value
Set gCell = gCell.Offset(1, 0)
End If
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,226,222
Messages
6,189,706
Members
453,566
Latest member
ariestattle

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