' ' 2つのシート間のワークシートへの参照を返す関数 ' Date: 1996/12/01 Author: Kazuyuki Housaka ' ' 引数 ' book1: ブックへの参照 ' sheetNameA : 開始ワークシート名 ' sheetNameB : 終了ワークシート名 ' ifInclude : Trueのとき、開始終了のワークシートを含む ' Option Explicit Function GetSheetsAtoB( _ book1 As Workbook, _ sheetNameA As String, _ sheetNameB As String, _ ifInclude As Boolean) As Object Dim nameArray() As String Dim i As Integer Dim ifStartExist As Boolean, ifEndExist As Boolean Dim sht As Worksheet i = -1 ifStartExist = False ifEndExist = False For Each sht In book1.Worksheets If ifStartExist Then If sht.Name = sheetNameB Then ifEndExist = True If ifInclude Then i = i + 1 ReDim Preserve nameArray(0 To i) nameArray(i) = sht.Name End If Exit For End If i = i + 1 ReDim Preserve nameArray(0 To i) nameArray(i) = sht.Name Else If sht.Name = sheetNameA Then ifStartExist = True If ifInclude Then i = i + 1 ReDim Preserve nameArray(0 To i) nameArray(i) = sht.Name End If End If End If Next If i > -1 And ifEndExist Then Set GetSheetsAtoB = book1.Worksheets(nameArray) Else Set GetSheetsAtoB = Nothing End If End Function Sub Test() Dim obj As Object Set obj = GetSheetsAtoB(ActiveWorkbook, "Sheet1", "Sheet3", True) If Not (obj Is Nothing) Then obj.Select End Sub