Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically freeze the top row of an Excel worksheet in Excel 2007 VBA?

I am looking to programmatically freeze the top row of an Excel worksheet from VBA. The end goal is to produce the same effect as the View > Freeze Panes > Freeze Top Row command in Excel 2007 so that the top row of the worksheet is frozen and users can see the top row of the worksheet even as they scroll through the data.

like image 975
LJ. Avatar asked Jul 12 '10 22:07

LJ.


People also ask

How do I freeze the top row in Excel 2007?

To freeze the top row, open your Excel spreadsheet. Select the View tab from the toolbar at the top of the screen and click on the Freeze Panes button in the Window group. Then click on the Freeze Top Row option in the popup menu. Now when you scroll down, you should still continue to see the column headings.

How do I freeze a row in Excel VBA?

If you want to freeze a row or a number of rows, meaning to be able to keep them visible as you scroll down, then do the following: Select the entire row below the last row of the rows you want to freeze. Go to View –> Freeze Panes –> Freeze Panes.

How do I freeze the top row in Excel without rows?

Select the cell below the rows and to the right of the columns you want to keep visible when you scroll. Select View > Freeze Panes > Freeze Panes.


1 Answers

Rows("2:2").Select ActiveWindow.FreezePanes = True 

Select a different range for a different effect, much the same way you would do manually. The "Freeze Top Row" really just is a shortcut new in Excel 2007 (and up), it contains no added functionality compared to earlier versions of Excel.

like image 161
Tomalak Avatar answered Sep 21 '22 05:09

Tomalak