Worksheet selection

B

Bishop

Dim wb As Workbook
Dim ws As Worksheet

For Each wb In Workbooks
'Test to see if wb's name is like "ExportedData*"
If wb.Name Like "ExportedData*" Then
'Create a worksheet object to reference the appropriate
'worksheet in the wb

'Why does this work...
Set ws = wb.ActiveSheet

'But this doesn't?
Set ws = wb.Worksheet("Tally sheet")

How do I make the second one work? Once I find the specified workbook I
need to select a specific sheet (Tally Sheet) in the workbook.
 
M

meh2030

Dim wb As Workbook
Dim ws As Worksheet

For Each wb In Workbooks
  'Test to see if wb's name is like "ExportedData*"
  If wb.Name Like "ExportedData*" Then
    'Create a worksheet object to reference the appropriate
    'worksheet in the wb

'Why does this work...
Set ws = wb.ActiveSheet

'But this doesn't?
Set ws = wb.Worksheet("Tally sheet")

How do I make the second one work?  Once I find the specified workbook I
need to select a specific sheet (Tally Sheet) in the workbook.

Bishop,

You are missing an "s" on the end of "Worksheet" in your second
example. It should read "Set ws = wb.Worksheets("Tally sheet")".

Best,

Matthew Herbert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top