Friday, April 11, 2008

Scroll to a position in Excel using VBA

Scroll Window using Excel VBA

Application.GoTo can be used to scroll to a specific location in Excel sheet. Application.GoTo selects any range or Visual Basic procedure in any workbook, and activates that workbook if it’s not already active.

Sub Scroll_To_A_Location()

Application.GoTo Sheets(3).Range("A200"), True

End Sub


This method differs from the Select method in the following ways:

If you specify a range on a sheet that’s not on top, Microsoft Excel will switch to that sheet before selecting. (If you use Select with a range on a sheet that’s not on top, the range will be selected but the sheet won’t be activated).

This method has a Scroll argument that lets you scroll through the destination window.
When you use the Goto method, the previous selection (before the Goto method runs) is added to the array of previous selections. You can use this feature to quickly jump between as many as four selections.
The Select method has a Replace argument; the Goto method doesn’t.

3 comments:

  1. Anonymous7:48 AM

    This works perfect! thanks!

    ReplyDelete
  2. Anonymous5:45 PM

    Hi Shasur,
    Indeed, works perfectly but I did not manage to make it working on a MS Office Spreadsheet control 11.0, residing on a mul├ętipage userform.
    I used following way around:
    Me.Spreadsheet1.ActivewWindow.ScrollRow=1
    Me.Spreadsheet1.ActivewWindow.ScrollColumn=1
    scrolling to row 1, column A and then Select the cell.
    If you would know how to make the GoTo work on the spreadsheet control, I would appreciate to know it.
    Thanks.
    Sich

    ReplyDelete
  3. Anonymous8:55 PM

    Thank you!

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...

Visual Basic for Applications (VBA) Forum (recent threads)

CodeKeep VBA Feed

Visual Studio Tools for Office Forum (recent threads)

Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.

Office Business Applications (OBA) Team Blog

MSDN Code Gallery Published Resources For Tag VSTO

microsoft.public.vsnet.vstools.office Google Group