carbonbased65
New Member
- Joined
- Nov 2, 2022
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi, I hope you are well.
I am trying to create a simple script to dynamically list all worksheets that have the text "Include" in cell A4 but am getting a Type Mismatch error.
I think it has something to do with using ws.Name in the Worksheets() expression because if I test this using a sheet name e.g. Worksheets("Nova") it will return all sheets (as Nova has "Include" in cell A4.
This script lists all the worksheet names perfectly if I do not use the if statement to refine the output.
Any assistance you can offer to resolve this would be most appreciated.
Thank You
BR
-Andrew
I am trying to create a simple script to dynamically list all worksheets that have the text "Include" in cell A4 but am getting a Type Mismatch error.
I think it has something to do with using ws.Name in the Worksheets() expression because if I test this using a sheet name e.g. Worksheets("Nova") it will return all sheets (as Nova has "Include" in cell A4.
This script lists all the worksheet names perfectly if I do not use the if statement to refine the output.
Any assistance you can offer to resolve this would be most appreciated.
VBA Code:
Sub list_sheets()
Dim ws As Worksheet
Dim msg As String
For Each ws In ThisWorkbook.Worksheets
If Worksheets(ws.Name).Range("A4") = "Include" Then
msg = msg & ws.Name & vbNewLine
End If
Next ws
MsgBox (msg)
End Sub
Thank You
BR
-Andrew