Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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: Floating Information in a Frozen Row.

Floating Information in a Frozen Row

Written by Allen Wyatt (last updated February 4, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

Bev has a worksheet with two header rows that are frozen and a column that is frozen. She can then scroll across the page adding data week by week. Names and subtotals are fixed on the left, week dates across the top. Above all this, in the first frozen row, Bev has a nice fancy title describing the workbook. She's looking for a way that she can have her title (the one in the first row) "float" so that when she scrolls across the page the title does not disappear off the edge of the visible worksheet.

The easiest way to do this is to make sure that the title is in cell A1. Since you have one column and two rows frozen, as you scroll to the right cell A1, containing the title, will always be visible on the screen. (This only works satisfactorily if the entire title fits into cell A1, without "spilling over" into cell B1 or beyond.)

If you want something a bit more fancy with your title, then you need to do a bit of work with text boxes and macros. If you place the title in a text box positioned in the first row, then you can use some macros to make sure that the text box is always centered on the screen in that row.

Let's assume, for the sake of this example, that the text box containing the title is called "TitleTextBox." As you scroll left and right in the worksheet, a macro could automatically check to make sure that the left edge of the text box is always equal to the left edge of the visible screen area. The following code needs to be added to the worksheet code for the worksheet containing the text box:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Me.Shapes("TitleTextBox").Left = ActiveWindow.VisibleRange.Left
End Sub

This macro, because it is part of the worksheet code, will run every time the selection is changed in the worksheet. Thus, when you use the arrow keys to move left or right, use the tab keys, or select a cell with the mouse, the macro will run and make sure that the left edges of the text box and the visible area always match up.

When this macro won't kick in is when you scroll left and right by using the horizontal scroll bar at the bottom of the screen. There is no "scroll event" that is triggered automatically when the scroll bars are used. Until a selection is made somewhere within the new visible range, thereby triggering the SelectionChange event, the textbox location will not be moved.

The only workaround to this limitation is to use Visual Basic's timer capabilities to update the textbox periodically. The following code does it every second, but you can adjust it to run less often, if desired. This code gets added to a regular VBA module:

Sub UpdateTB()
    If ActiveSheet.Name = "Sheet1" Then
        ActiveSheet.Shapes("TitleTextBox").Left = _
          ActiveWindow.VisibleRange.Left
    End If
    Application.OnTime Now + TimeSerial(0, 0, 1), "UpdateTB"
End Sub

And this gets added to the workbook object to start the timer when the workbook is first opened:

Private Sub Workbook_Open()
    UpdateTB
End Sub

If you use the timer-based approach to positioning the text box, you won't need to use the one that is tied to the SelectionChange event. The timer version simply adjusts the title after every interval.

There is an additional "downside" to either macro-based technique besides any sluggishness introduced by the code running: every time the code runs it clears the "undo stack." This means that you won't be able to "undo" changes that you make to the workbook if you need to.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10260) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Floating Information in a Frozen Row.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Pulling All Fridays

It can be handy to know when specific weekdays occur within a range of dates. Figuring out this information, using ...

Discover More

Using a Single Instance of Excel with Two Monitors

Working on a computer system that has multiple monitors can help increase your productivity. If you want to work with ...

Discover More

Changing the Attached Template

Templates, when attached to a document, can greatly affect how that document looks. You can change from one template to ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Inserting and Copying Rows

Want an easy way to insert a new row in a worksheet and copy everything from the row above? (You end up with two ...

Discover More

Spreading Out Worksheet Rows

If someone sends you a worksheet that has lots of data in it, you might want to "spread out" the data so you can have ...

Discover More

Deleting Blank Columns

Import data from another program, and you could end up with a lot of blank columns in your data. Here's the quickest way ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 7?

2014-10-28 07:20:50

Tomo

Thx Brian Canes!


2014-10-25 17:29:15

Brian Canes

Here http://bit.ly/LogoFloat is a method that does not involve any VBA.
Place logo in new worksheet. Ribbon>View>uncheck Gridlines>uncheck Headings
Ribbon>View>New Window>Arrange All>Windows of Active Workbook>Horizontal
Resize and position the logo window at the top. You can widen it so that the vertical scrollbar may be hidden. You can scoot it up so that the title bar is hidden.
Resize and position the data window. Let the top of the data window cover the tab and horizontal scroll bar of the logo window.
You can also do freeze panes or splits in the data window.
This method also lets you have the logo 'float' at the bottom or sides. Or any combination. In my sample, I show a side bar to the left.
Regards
Brian
PS - another useful tip is generatedata.com


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.