I am trying to adjust the code so that it cycles through the sheets using a range variable rather than hard coding Range ("O4"). However, when I run the code, it works on the first sheet and then gives me a run-time error '1004' when it gets to "MyRange.Select" - Any ideas what I am doing wrong here?
Code:
Sub AllWorkSheets()
Dim ActSheet As Worksheet
Dim Junction As String
Dim BOC As String
Dim Amount As String
Dim MyRange As Range
Set MyRange = ActiveCell
'' Added the MyRange Variable to replace the hard coded Values below used in Amount and Range
Sheets("Aggregate").Activate
Set ActSheet = ActiveSheet
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If Left(ws.Name, 8) = "Junction" Or Left(ws.Name, 8) = "National" Then
ws.Select
' Blocked and copied code while I test
'Amount = Range("O4").Value
'Range("O4").Activate
'Amount = Range("O4").Value
Amount = MyRange.Value
MyRange.Select
Amount = MyRange.Value
BOC = ActiveCell.Offset(0, -12).Value
Junction = ActiveCell.Offset(0, -14).Value
ActSheet.Select
Range("B1").Value = "BOCs"
Range("A1").Value = "Junction Num"
Cells(Rows.Count, 1).End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Value = Junction
ActiveCell.Offset(0, 2) = Amount
ActiveCell.Offset(0, 1) = BOC
End If
Next
End Sub