+ Reply to Thread
Results 1 to 7 of 7

Move Screen to mimic active sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Move Screen to mimic active sheet

    Hi Guys,

    I have a spreadsheet, where I have identical tabs (same column widths, same titles on columns, etc), the only difference is a few values. I want to be able to flick between the sheet1 and sheet2 quickly and be in the same viewing location when I go to the other sheet.

    eg: What I need is when I move from sheet1 to sheet2, for the view to be the same.

    If I'm viewing sheet1 and move the screen to show ColumnG to ColumnZ, and then click on sheet2, sheet2 will show whatever sheet2 last showed. I need sheet2 to also show ColumnG to ColumnZ when I click on it; so that I can quickly determine what is different between the two sheets.

    I hope that makes sense.
    Thanks guys,
    Thanks,

    JimmyWilliams

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Move Screen to mimic active sheet

    Put this in the ThisWorkbook code module. Change the sheet names to suit.

    Dim ScrRow As Long, ScrCol As Long, bIgnor As Boolean
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
         Dim sh1 As Worksheet, sh2 As Worksheet
         If Not bIgnor Then
            Set sh1 = Sheets("Sheet1")
            Set sh2 = Sheets("Sheet2")
            bIgnor = True
            Select Case Sh.Name
                Case sh1.Name, sh2.Name
                    If Sh Is sh1 Then sh2.Activate Else sh1.Activate
                    ScrRow = ActiveWindow.ScrollRow
                    ScrCol = ActiveWindow.ScrollColumn
                    Sh.Activate
                    ActiveWindow.ScrollRow = ScrRow
                    ActiveWindow.ScrollColumn = ScrCol
            End Select
            bIgnor = False
         End If
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Move Screen to mimic active sheet

    Hi AlphaFrog,

    what you have given is a good start, I'm working on trying to fit your code.

    I'm wondering if there is a way to get "the sheet you just left" (eg, similar to "activesheet" but instead something like "sheet that was active before current activesheet").
    I have 5 sheets all similar (and then other tabs that are not similar) and I want whatever sheet's view (if its 1 of the 5 similar ones) to then be 'pushed' onto the other 4 sheets, just before you switch sheet.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Move Screen to mimic active sheet

    Dim ScrRow As Long, ScrCol As Long, bIgnor As Boolean, shPrevious As Worksheet
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
         Dim sh1 As Worksheet, sh2 As Worksheet
         If Not bIgnor Then
            bIgnor = True
            If Not shPrevious Is Nothing Then
                Select Case Sh.CodeName
                    Case "Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5"
                        shPrevious.Activate
                        ScrRow = ActiveWindow.ScrollRow
                        ScrCol = ActiveWindow.ScrollColumn
                        Sh.Activate
                        ActiveWindow.ScrollRow = ScrRow
                        ActiveWindow.ScrollColumn = ScrCol
                End Select
            End If
            bIgnor = False
         End If
    End Sub
    
    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
        Select Case Sh.CodeName
            Case "Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5"
                Set shPrevious = Sh
        End Select
    End Sub

  5. #5
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Move Screen to mimic active sheet

    *Removing Post because not needed*
    Last edited by JimmyWilliams; 03-12-2020 at 08:51 AM. Reason: Comment not needed

  6. #6
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Move Screen to mimic active sheet

    Hi AlphaFrog,

    OMG, that code is so awesome!
    Seriously, you're awesome!

    However, I have another layer of problem:
    As you can guess:
    "69%C 31%P",
    "63%C 37%P",
    "56%C 44%P",
    "50%C 50%P",
    "44%C 56%P" need to look the same.

    The same spreadsheet also has:
    "Long forecast -70% 30%P",
    "Long forecast -50% 50%P",
    "Long forecast -0% 100%P" need to look the same as each other too. (but are unrelated to "XX%C XX%P")

    The same spreadsheet also has:
    "Test Num 01"
    "Test Num 02"
    "Test Num 03" need to look the same as each other too. (but are unrelated to "XX%C XX%P" and unrelated to "Long forecast - XX%C XX%P")

    I'm hoping that if you help me with this code, I'd be able to expand it to create N different "groups" of tabs within a workbook.
    Please and thank you!
    Last edited by JimmyWilliams; 03-12-2020 at 09:45 AM. Reason: Making comment neater.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Move Screen to mimic active sheet

    You're welcome.

    I have no idea what the rest means. Sounds like a whole new question. It would be best to start a new thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA: dashboard sheet screen remains active/displays 24/7 eventhough no activity
    By Sharonjit in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-20-2018, 09:29 AM
  2. [SOLVED] Mimic Font Color Picker - Apply Active(?) Color
    By delaing in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-26-2017, 02:41 PM
  3. [SOLVED] move active sheet after LastSheet
    By plans in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2016, 04:48 PM
  4. Mimic highlighted cells onto different sheet
    By rz6657 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-01-2012, 01:51 PM
  5. [SOLVED] Move Cell in non active sheet to specific range
    By pradeepdeepu_001 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2012, 11:21 AM
  6. Replies: 2
    Last Post: 12-11-2008, 10:18 AM
  7. Replies: 1
    Last Post: 06-18-2005, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1