Typically a blank estimation workbook contains 9 sheets before data entry sheet CS1 (which is always present), x number of CS sheets (where x could be 50, 100, 200 etc.) and zero sheets after the last CS sheet. Occasionally users will add sheets before and after the last CS sheet but are not permitted to add sheets between the first and last CS sheet.
The requirement is to refine existing VLOOKUP code (which currently looks at avery sheet in the workbook) to only look at all the CS sheets. Therefore the need to find how many named "CSn" (where n is an integer from 1 to unknown) sheets are within a workbook. This is easy if the CS sheets are at the end of the workbook but not so easy if the user adds other sheets after the last CS sheet.
I can't figure out how to determine the last CS sheet index as the number of CS sheets varies.
Quick code to display number of CS sheets
Public Sub No_of_Sheets()
intCount = ActiveWorkbook.Sheets.Count 'Find total number of workbook sheets
intCS1_Index = Sheets("CS1").Index 'CS1 Sheet index
intCSCount = intCount - (intCS1_Index - 1) 'Find total number of CS sheets
nonCSSheets = intCount - intCSCount 'Find total number of Non-CS sheets
MsgBox " CS1 Sheet Index = " & intCS1_Index
MsgBox " CS Sheet Count = " & intCSCount
MsgBox " Non CS Sheet Count = " & nonCSSheets
End Sub