Sub SMC()
Const strSheetStart As String = "Sheet3"
Const strSheetEnd As String = "Sheet2"
Dim sht As Object
For Each sht In Sheets
If lng Then
lng = lng + 1
End If
If sht.Name = strSheetStart Then
lng = lng + 1
ElseIf sht.Name = strSheetEnd Then
Exit For
End If
Next sht
If lng >= 2 Then
MsgBox "There is(are) " & lng - 2 & " sheet(s) in between sheets '" & strSheetStart & "' and '" & strSheetEnd & "'", vbOKOnly, ""
Else
MsgBox "Are you sure your sheet references are in order? Please check and try again.", vbOKOnly, ""
End If
End Sub
Function SMC(Optional p1 As String = "", Optional p2 As String = "")
Application.Volatile
Dim ind1 as Integer , ind2 as Integer
p1 = IIf(p1 = "", ThisWorkbook.Sheets(1).Name, p1)
p2 = IIf(p2 = "", ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name, p2)
ind1 = Application.WorksheetFunction.Min(Sheets(p2).Index, Sheets(p1).Index)
ind2 = Application.WorksheetFunction.Max(Sheets(p2).Index, Sheets(p1).Index)
SMC = ind2 - ind1 - 1
End Function
Function SMC(Optional p1 As String, Optional p2 As String) As Long
Application.Volatile True
With ThisWorkbook
If p1 = "" Then p1 = .Sheets(1).Name
If p2 = "" Then p2 = .Sheets(.Sheets.Count).Name
SMC = Abs(.Sheets(p2).Index - .Sheets(p1).Index) - 1
End With
End Function
mgao77 cross posting is frowned on by many forums
please read the Key Masters post on forum etiquette.
http://chandoo.org/forum/threads/new-users-please-read.294/
Application.Volatile true