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
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