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

calendar_today Asked Jul 12, 2010
thumb_up 25 upvotes
history Updated April 16, 2026

Question posted 2010 · +26 upvotes

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.

Accepted answer +25 upvotes

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.

Top excel-vba Q&A (6)

+25 upvotes ranks this answer #15 out of 136 excel-vba solutions on this site — top 11%.