ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet selection (https://www.excelbanter.com/excel-programming/428791-worksheet-selection.html)

Bishop

Worksheet selection
 
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.

Jacob Skaria

Worksheet selection
 
Try

Set ws = wb.Worksheets("Tally sheet")
--
If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

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.


[email protected]

Worksheet selection
 
On May 21, 12:22*pm, Bishop wrote:
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


All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com