EXCEL VBA 指定ブックについて全シートの選択セルの位置を左上に移動する。
サンプル
Sub Macro1() Call msub全シートのアクティブセルを一番上に(ActiveWorkbook) End Sub
' 指定ブックについて全シートの選択セルの位置を左上に移動する。 ' '引数 ByVal wkbTarget As Workbook 対象ブック ' 'URL https://pgbigoroku.hatenablog.com/entry/2022/08/18/232729 '2022/8/18 Public Sub msub全シートのアクティブセルを一番上に(ByVal wkbTarget As Workbook) Dim intFor As Integer With wkbTarget For intFor = .Worksheets.Count To 1 Step -1 If .Worksheets(intFor).Visible = xlSheetVisible Then Call nsubワークシートのアクティブセルを一番上に(.Worksheets(intFor)) End If Next End With End Sub ' 指定シートについて選択セルの位置を左上に移動する。 ' '引数 ByRef wksTarget As Worksheet 対象シート ' 'URL https://pgbigoroku.hatenablog.com/entry/2022/08/18/232729 '2022/8/18 Public Sub nsubワークシートのアクティブセルを一番上に(ByRef wksTarget As Worksheet) Dim intFor As Integer Dim lngBeforeRow As Long Dim intBeforeCol As Integer With wksTarget .Parent.Activate .Select .Range("A1").Select If .Range("A1").Locked = True Then If ActiveSheet.ProtectContents = True Then For intFor = 1 To 30000 ActiveCell.Next.Activate If lngBeforeRow = ActiveCell.Rows.Row Then If intBeforeCol = ActiveCell.Columns.Column Then Exit Sub End If End If lngBeforeRow = ActiveCell.Rows.Row intBeforeCol = ActiveCell.Columns.Column If ActiveCell.Width = 0 Then ElseIf ActiveCell.Height = 0 Then Else Exit For End If Next End If End If End With End Sub