Forum Discussion

DylanBrown's avatar
DylanBrown
Copper Contributor
Aug 12, 2024
Solved

Auto-scroll an Excel workbook

Hi Guys,

 

Looking for some assistance, I am hooking up a mini PC to a Samsung Smart TV to display an Excel spreadsheet, bascially highlights what projects we have on and some info in a table.

 

The issue is, it won't all fit on one page, is there anyway of the workbook auto scrolling to the bottom of the table and then starting from the top again?

 

I'm presuming you can through VBA but not used it too much so if someone has a guide or a method of doing this so it looks professional in the office please let me know. Just incase this matters too, this document will be stored on a sharepoint site and opened live, not sure if the VBA carries over but users will be updating this table via their own machines and hopefully the one on the TV will update automatically.

 

Thanks

  • DylanBrown It should continue to run just fine, the code looks at the current size of the table each time it runs.

6 Replies

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor

    DylanBrown You can do this with a bit of VBA code (paste into a normal module):

     

    Option Explicit
    
    Dim nextTime As Double
    
    Sub scrollAgain()
        Dim curVisLastRow As Long
        curVisLastRow = ActiveWindow.VisibleRange(ActiveWindow.VisibleRange.Cells.Count).Row
            With ActiveSheet.ListObjects(1)
            If curVisLastRow < (.ListRows.Count + .Range.Cells(1, 1).Row) Then
                ActiveWindow.SmallScroll Down:=1
            Else
                ActiveWindow.SmallScroll up:=curVisLastRow - 1
            End If
        End With
        nextTime = Now + TimeValue("00:00:01")
        Application.OnTime nextTime, "scrollAgain"
    End Sub
    
    Sub StopScrolling()
        On Error Resume Next
        Application.OnTime nextTime, "scrollAgain", , False
    End Sub

     

     

    Start the scrolling by running the scrollAgain macro (alt+F8 from Excel, click on macroname and hit Run).

    Stop it by running StopScrolling.

     

    To make this slower, adjust the "00:00:01"

     

    By the way: the code assumes your table is "Formatted as table".

    • DylanBrown's avatar
      DylanBrown
      Copper Contributor

      JKPieterse - Thanks for this, I've just tried to run this now but I get the below error. Do I need to change something in the code to suit my workbook?

       

      • DylanBrown's avatar
        DylanBrown
        Copper Contributor
        Ah nevermind, I didn't put it in a new module, that seems to be working now, thank you. Is there any risk of excel crashing if this is set to this permanent?

        Also, we have this document in a shared library, so people will be adding data to it, if this is opened whilst people make amendments will it update live or will I need to add some VBA to update the doc every minute for example?

        Thanks
  • GeorgieAnne's avatar
    GeorgieAnne
    Iron Contributor

    Hello @DylanBrown
    You definitely should start working in VBA. If you want to have all the fun that is.
    On the Web there are plenty of examples of what you want to do, here are some examples:
    https://forum.ozgrid.com/forum/index.php?thread/86754-scroll-screen-to-active-cell-row/
    https://www.automateexcel.com/vba/scroll/
    https://stackoverflow.com/questions/12636434/how-do-i-make-an-excel-worksheet-scroll-to-a-row-programatically

    You could also write some code to remove the row of a completed task from the display.

    Let me know if you need more help understanding the code or adjusting it to your needs.
    TAKE THE PLUNG you will not regret it at all 😉

    GiGi

    • DylanBrown's avatar
      DylanBrown
      Copper Contributor
      I have done a little VBA a while ago but not for anything like this. Would I need some sort of trigger to start the scrolling? I'm planning on having this always on on the TV so it doesn't turn off but just in case it does I don't want it to be a nightmare to start the code again.

      I'm just reading through this one that you shared now - https://www.automateexcel.com/vba/scroll/

      Little confused where to start.

Resources