mhdakhtar8
New Member
- Joined
- Feb 4, 2013
- Messages
- 36
Hi,
I'm in a situation where I need to check if some sheets already exist in a workbook which I need to run a macro on. That macro is designed for selected sheets. If any of the sheet is not existing, it will fail.
I want to put a control for VBA to check whether those sheets already exists or not.
Here's what I've reached to so far but It's giving me Compile error for sname.Length. The condition is I only want sheet name to be checked from Array for existence.
I'm in a situation where I need to check if some sheets already exist in a workbook which I need to run a macro on. That macro is designed for selected sheets. If any of the sheet is not existing, it will fail.
I want to put a control for VBA to check whether those sheets already exists or not.
Here's what I've reached to so far but It's giving me Compile error for sname.Length. The condition is I only want sheet name to be checked from Array for existence.
Code:
Sub Generate_Producitvity_Report()
Dim OW As Workbook, ws As Worksheet, sname() As String, i As Integer
sname = Array("COS REJECT", "APPROVAL SENT", "Pending Client Response", "Awaiting Four-Eye Check", "Awaiting RDS Approval", "SHEET6", "SHEET1")
Set OW = ActiveWorkbook
For Each ws In ThisWorkbook.Worksheets
ws.Select
With ws
[COLOR="#FF0000"]For i = 0 To sname.Length[/COLOR]
If ws.Name <> sname(i) Then
MsgBox sname(i) & " sheet not found"
End If
Next i
End With
Next ws
End Sub