Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Positioning a Column on the Screen.
by Allen Wyatt
(last updated December 6, 2014)
Riek encountered a problem while developing a macro that sets up the screen for user input. Columns A:G always need to stay on the screen, so his macro freezes those columns. He then issues a command to move to column Z to start input. This places columns T:Z to the right of the frozen columns A:G. What Riek really wants is for columns Z:AF to appear to the right of A:G, but he doesn't know how to accomplish that.
There are several ways that the desired results can be achieved. The first is to simply move "past" the desired target, and then move back to it, as in the following macro:
Sub GotoCol1() With Application ActiveWindow.FreezePanes = False Range("H1").Select ActiveWindow.FreezePanes = True .Goto Range("IV1") .Goto Range("Z1") End With End Sub
The important code lines are those that use the Goto method. The first jump is to the last cell of the first row, and the second jump moves back to the true target, Z1. By moving in this way, column Z ends up just to the right of the frozen range, A:G.
While this works just fine, a better solution would be to use the Scroll parameter with the Goto method. Consider the following example:
Sub GotoCol2() With Application ActiveWindow.FreezePanes = False Range("H1").Select ActiveWindow.FreezePanes = True .Goto Reference:=Range("Z1"), Scroll:=True End With End Sub
The Scroll parameter is optional with the Goto method; it defaults to False. If you set it to True, then Goto scrolls through the window so that the upper-left corner of the target range (Z1) appears in the upper-left corner of the window.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10523) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Positioning a Column on the Screen.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
The macro programming language used in Excel gives you a great many tools that allow you to modify the way that Excel appears ...Discover More
When processing information using a macro, you may need to know if there are any other instances of Excel running on a ...Discover More
Excel allows you to add pictures to your worksheet, even within a macro. However, you might have a bit harder time figuring ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.