I have tried to write code to Move to A2 from Sheet BR1 Sales to Southern Sales when A2 is select on sheet BR1 Sales
When I select A2 on sheet Br1 Sales, I get "select method of class failed:
It would be appreciated if someone could kindly amend my code
When I select A2 on sheet Br1 Sales, I get "select method of class failed:
It would be appreciated if someone could kindly amend my code
Code:
rngA2.Select ' Select cell A2
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$2" Then
MoveSheetsToA2
End If
End Sub
Private Sub MoveSheetsToA2()
Dim ws As Worksheet
Dim startSheet As Worksheet
Dim endSheet As Worksheet
Dim rngA2 As Range
Set startSheet = ThisWorkbook.Sheets("BR1 Sales")
Set endSheet = ThisWorkbook.Sheets("Southeern Sales")
Set rngA2 = startSheet.Range("A2")
Application.ScreenUpdating = False ' Disable screen updating for better performance
' Move all sheets from startSheet to endSheet
For Each ws In ThisWorkbook.Sheets
If ws.Index >= startSheet.Index And ws.Index <= endSheet.Index Then
ws.Activate ' Activate the sheet
rngA2.Select ' Select cell A2
End If
Next ws
startSheet.Activate ' Activate the startSheet
Application.ScreenUpdating = True ' Enable screen updating
rngA2.Select ' Select cell A2
End Sub