0
votes

What I am trying to do seems basic enough, however I don't know where I am going wrong with the code.

I want to run the selected cell through a loop of the worksheets and select the worksheet that matches the selected cell located in cell B1.

Dim SelectedCell as Range
Dim ws As Worksheet
Set SelectedCell = Range(ActiveCell.Address)
For Each ws In ActiveWorkbook.Worksheets
If ws.Range("B1").Value = SelectedCell.Value Then
ActiveSheet.Select
End If
Next ws
End Sub

Thanks in advance for all the help!

2

2 Answers

1
votes

Try instead

Dim ws As Worksheet
SelectedCell = ActiveCell
For Each ws In ActiveWorkbook.Worksheets
  If ws.cells(1,2) = SelectedCell Then
    ws.Select
  End If
Next ws
End Sub
0
votes

Select cell run macro will select the sheet name that matches the selected cell. (Case sensitive)

Dim SelectCell As String
Dim ws As Worksheet
SelectCell = ActiveCell.Value2
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name = SelectCell Then
        ws.Select
    End ID  
    Next ws