Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Attempting a macro that will set all selected sheets to have same cells visible as in the active sheet.

Example: if top-left cell is L76 on active sheet, then running this macro will set all selected worksheets to show L76 as the top left cell.

Cobbled this code together from examples found online but not sufficiently advanced in VBA to make it work.

Sub SetAllSelectedSheetsToSameRowColCell()
    Dim rngSel As Range
    Dim intScrollCol As Integer
    Dim intScrollRow As Long
    Dim oSheet As Object
    If TypeName(Sh) = "Worksheet" Then
        Set oSheet = ActiveSheet
        Application.EnableEvents = False 'Unsure what this line is for
        Sh.Activate
        With ActiveWindow
            intScrollCol = .ScrollColumn
            intScrollRow = .ScrollRow
            Set rngSel = .RangeSelection
        End With
        oSheet.Activate
        Application.EnableEvents = True
    End If

    'Loop thru rest of selected sheets and update to have same cells visible
    Dim oWs As Worksheet
    For Each oWs In Application.ActiveWindow.SelectedSheets
        On Error Resume Next
        oWs.Range(rngSel.Address).Select
            .ScrollColumn = intScrollCol
            .ScrollRow = intScrollRow
    Next

End Sub

References:

https://excel.tips.net/T003860_Viewing_Same_Cells_on_Different_Worksheets.html

VBA Macro To Select Same Cell on all Worksheets

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
179 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this:

Sub ResetAllSheetPerspectives()
    Dim ws As Worksheet
    Dim lRow As Long
    Dim lCol As Long
    Dim dZoom As Double

    lRow = ActiveWindow.ScrollRow
    lCol = ActiveWindow.ScrollColumn
    dZoom = ActiveWindow.Zoom

    For Each ws In Application.ActiveWindow.SelectedSheets
        ws.Activate
        ActiveWindow.Zoom = dZoom
        Application.Goto ws.Cells(lRow, lCol), True
    Next ws
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...