I am trying to create almost a "sheet validate" code in which it will cycle through the current workbooks sheets to make sure it matches to the defined array.
I have the initial part of the code where it takes all the sheets in the current workbook and puts them in an array. My problem lies around the Application.Match when comparing it to the defined array or hardcoded array.
I am using CodeNames for the sheets to make it more accurate if a user deletes a sheet, inserts a new one and renames it the same as the deleted.
All I am really looking for is to give me a message box of the missing value from the defined array if it doesn't exist in the current workbook.
I am also avoiding any writing of values in the workbook.
I have the initial part of the code where it takes all the sheets in the current workbook and puts them in an array. My problem lies around the Application.Match when comparing it to the defined array or hardcoded array.
I am using CodeNames for the sheets to make it more accurate if a user deletes a sheet, inserts a new one and renames it the same as the deleted.
All I am really looking for is to give me a message box of the missing value from the defined array if it doesn't exist in the current workbook.
I am also avoiding any writing of values in the workbook.
Code:
Sub ArraySheets()
Dim SheetNames() As Variant
Dim i As Long
Dim a As String
Dim iArray() As Variant
iArray = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9", "Sheet10", "Sheet11", "Sheet13", "Sheet14", "Sheet15", "Sheet16", "Sheet17", "Sheet18", "Sheet20", "Sheet21", "Sheet22", "Sheet26")
Dim TotalArray As Variant
For i = 1 To Sheets.Count
a = Sheets(i).CodeName
ReDim Preserve SheetNames(1 To i)
SheetNames(i) = a
a = ""
Next i
For i = LBound(SheetNames) To UBound(SheetNames)
If Error(Application.Match(SheetNames(i), iArray, 0)) Then
TotalArray = SheetNames(i) & vbNewLine
End If
Next i
MsgBox (TotalArray)
end sub
Last edited: