1
votes

Is it possible to activate a sheet in an opened workbook through VBA without knowing it's name? I'm opening a workbook using application.getfileopenname and reading data from it, but some of the workbooks have the data on the second sheet, instead of the first. Is there anyway I could switch the active worksheet to the second sheet?

1
try yourWorkBook.Worksheets(2).ActivateDaniel Dušek

1 Answers

2
votes
Dim wsData As Worksheet
Set wsData = Sheets(1)

'If the Range doesn't have the value you are looking for switch sheets
If wsData.Range("A1").Value <> "MyExpectedData" Then Set wsData = Sheets(2)