+ Reply to Thread
Results 1 to 21 of 21

VBA to have certain sheets scroll simultaneously

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    VBA to have certain sheets scroll simultaneously

    Hi all,

    I'm currently trying to figure out if there is a way to have several sheets (not all) move simultaneously.

    e.g.

    If I scroll within the sheet "China" to the following position


    .ScrollColumn = 34
    .ScrollRow = 85
    ActiveWindow.Zoom = 100


    then I want the code to move it to the same row and column position in sheet "China", "Korea", "HK Hub" etc. as well without having to select each of the sheets and doing it manually, so all sheets in the array will thus ALWAYS have the same window position and zoom, which would help me tremendously when comparing data and switching between sheets...

    I found the below code to do that, unfortunately it does not seem to work. Maybe it's just an easy fix as I'm new to the macro world? Can someone have look?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to have certain sheets scroll simultaneously

    You need to add back your names to the array...
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    That works!!! brilliant! Thanks!

    The only slight problem I am experiencing (and maybe I am doing it wrong) is it only moves it to the same position if I go to the VBA window and run it manually every time. Is there a way to have it permanently run in the background so that it constantly updates the column/row position of all sheets in the array? I have pasted the code in the "ThisWorkbook" section, I suppose that is correct?

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to have certain sheets scroll simultaneously

    That's the nub of the problem. Excel has no Scroll event so the code can't run automatically - in any case scrolling all the 'linked' sheets every time one changes just eats resources and slows things down.

    One possible solution is to only run the code when a worksheet is activated, and then only for the sheet that was activated but you need some sort of reference point - will have a look later, no access to Excel at the moment.

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to have certain sheets scroll simultaneously

    For once, something a little more interesting than the normal "Why do I get a 'Next' without 'for'" type of question.

    I've no idea if this is the most efficient way of doing this but I just worked it through from 'top to bottom' without bothering to analyse things but I believe this will work as you want.

    In summary, there's a list of names of those sheets you want to monitor:
    Please Login or Register  to view this content.
    Add to/Remove from that list as needed. Note you just add the name without quotes or commas, even if it includes spaces (See 'HK Hub' as an example - There is an obvious issue with the way this is coded in that a sheet named 'Hub' (or 'TTL' or 'APAC') will also be found but I don't think this is very likely).

    When the workbook is opened, it will check if the active sheet appears in the list, if so it sets a reference to that using the variable LastSheet. If the active sheet is not one of the ones you want to monitor then it needs one to be choosen as the deffault. I used China but pick any...

    Then, as you activate different sheets, it will get the settings from LastSheet to apply to the newly activated sheet. This means only 1 sheet is updated and only when activated, a bit more efficient than the initial approach.

    This has limited testing only, time constriants and all that, but it seems to work.

    The code below must be placed in the ThisWorkbook module or else it will not work (you can remove any other procedures you might have hanging around to do this), and is commented to explain why it does what it does.


    Please Login or Register  to view this content.
    Last edited by cytop; 07-14-2017 at 06:24 AM.

  6. #6
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    I'm glad to hear I am asking more interesting/ challenging questions than others I will have a lot more 'complex' VBA request in the future, as my company does not currently have a macro expert employed!

    I'm impressed! That actually works! I'm experiencing a slight 1/3 of a second screen flickering, but that is minor...

    I have pasted it into the "ThisWorkbook" section as I understand it needs the "workbook open" sub, but unfortunately I do already have some code in there (mainly combo boxes and password protection), can I just combine the two or how do I solve that problem? It obviously currently only works if I remove the other code.

    Thanks for your help with this!!!

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to have certain sheets scroll simultaneously

    Just combine them - nothing in the Workboook_Open event I posted will interfere with anything you have done.

    If you are not selecting any sheets with your current code then just add mine anywhere - if you are, then I guess you add it at the end to take account of any sheet switching in your code but I don't think it'll matter where it goes in the procedure.

    does not currently have a macro expert employed
    I'm available - always did want to get back to to see the changes

  8. #8
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    Thanks!! will try it out on Monday!

    and interested in moving to Hong Kong ;-)? we are currently looking for someone!

  9. #9
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to have certain sheets scroll simultaneously




    ....

  10. #10
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    So... just tried and don't seem to get it right when combining it with my other code in the workbook_open event. Still not very familiar with vba codes especially the 'Option Explicit' part. This part of the code seems to be interfering with my code as it shows me a "variable not defined error" message

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to have certain sheets scroll simultaneously

    Using 'Option Explicit' means you have to declare all variables before use. It is a way of ensuring you don't mistype a variable name, leading to errors. For example:

    Please Login or Register  to view this content.
    That is an infinite loop as iTemp never gets to be greater than 10.

    You can either go back and declare all the variables or remove the Option Explicit statement. I'd recommend the first, you'll probably do the second

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA to have certain sheets scroll simultaneously

    just curious
    Synchronous scrolling (either full screen using dual monitor setup or side by side split) lets do this without all this VBA work required in the background
    why don't you just use that?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  13. #13
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    Quote Originally Posted by cytop View Post
    You can either go back and declare all the variables or remove the Option Explicit statement. I'd recommend the first, you'll probably do the second
    Since you are the expert and I want to learn how to write clean code, let's go for option 1 and declare all variables. Would I just have to add "
    Please Login or Register  to view this content.
    " to the option explicit code and then place that at the very top before the workbook_open event? Is there anything else in my other code that would need to be fixed?

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    Quote Originally Posted by humdingaling View Post
    just curious
    Synchronous scrolling (either full screen using dual monitor setup or side by side split) lets do this without all this VBA work required in the background
    why don't you just use that?
    Since I am trying to scroll simultaneously among different sheets within one (!) workbook, that won't work as far as I am concerned...?

  15. #15
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA to have certain sheets scroll simultaneously

    nope you can open the same workbook multiple times
    the method to this just varies slightly depending on what version of excel you are using

  16. #16
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    Quote Originally Posted by humdingaling View Post
    nope you can open the same workbook multiple times
    the method to this just varies slightly depending on what version of excel you are using
    Which would already be a problem, since this is a huge file that tends to crash even if just one is open...! The code works pretty well, so that would perfectly solve it, I just need to figure out how to combine it with my previous code in the "ThisWorkbook" section... Can you or anyone spot the mistake in my code above?

  17. #17
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA to have certain sheets scroll simultaneously

    you will find opening a new window for the same file less resource intensive than adding a whole bunch of code in to replicate something that Excel does natively

    i use the side by side method on 50mb+ files without much issues
    freeze frames etc are a little tricky to get around though

    anyways to the code
    without having to setup an exact replication of your spreadsheet
    i cannot parse your code properly

  18. #18
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA to have certain sheets scroll simultaneously

    Please Login or Register  to view this content.
    this should be probably outside (and before) the Workbook Open

  19. #19
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: VBA to have certain sheets scroll simultaneously

    Quote Originally Posted by esbencito View Post
    Which would already be a problem, since this is a huge file that tends to crash even if just one is open...!
    maybe we can address the core issue (and other possible future end issues) by helping to address that. Do you really have that much data stored in it? (in which case is excel the right platform?) or is it that you are doing a massive amount of calculations in it?
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  20. #20
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: VBA to have certain sheets scroll simultaneously

    Maybe it could be something as simple as doing something on a SheetDeactivate event under the ThisWorkbook object - something along the lines of the following.

    Please Login or Register  to view this content.
    P/S: Apologies for jumping in abruptly midway.
    Last edited by quekbc; 07-18-2017 at 01:56 AM.

  21. #21
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to have certain sheets scroll simultaneously

    Sorry for the late reply. Just solved it myself!! It was an easy fix in the end, but since I'm still new to macros, it took me a while to figure it out.

    Below code is the one I'm using now:

    Please Login or Register  to view this content.

    So, the code is working now, but I can notice a significant screen flickering when selecting a new sheet, is there a way to optimise this code further and reduce the flickering?

+ 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. [SOLVED] Simultaneously add sheets to multiple workbooks
    By dorkydancer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 11:31 AM
  2. Hiding rows in all sheets simultaneously
    By marcelonakamura in forum Excel General
    Replies: 1
    Last Post: 08-31-2011, 02:33 PM
  3. How to use advanced filter simultaneously in few sheets
    By markos17 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2011, 11:58 AM
  4. Format multiple sheets simultaneously with macro?
    By Synthia in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-14-2010, 12:44 PM
  5. Scroll Multiple Sheets to the Same Position Simultaneously
    By smlaff01 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-20-2007, 02:28 PM
  6. [SOLVED] How do I set print areas for multiple sheets simultaneously?
    By Twirly in forum Excel General
    Replies: 3
    Last Post: 01-09-2006, 08:20 AM
  7. How to apply the same background to many sheets simultaneously.
    By Colin Hayes in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 09-06-2005, 07:05 AM
  8. Replies: 1
    Last Post: 06-20-2005, 08:05 AM

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