Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

freezing the top row of a sheet with a macro

Status
Not open for further replies.

jjfjr

Programmer
Mar 10, 2004
13
US
Hi;

I have a workbook with three sheets - Search Form, Results and Data Table. The search form allows the user to type in information into one of ten fields. Each field is aasociated with a column in the data table ; any hits go into the results sheet. The header row of the data table goes in as the top row of the results sheet. I'd like to freeze the results top row so that when someone scrolls through, the top row (A1 to J1) stays on top so the user can see the column descriptions. Also. I'd like to have the header row of the results sheet print out no matter where the user has scrolled to.

Someone had told me to put in the following code as part of my Search button code:

Sheet3.Activate
Sheet3.Range("A2").Select
ActiveWindow.FreezePanes = True

The Results sheets does freeze the top row, specifically cells A1 to J1. However, when I scroll, it seems that the entire area of A1 to J6 is frozen. Also, when I try to scroll horizontally, the entire columns A through E are also frozen. As I said before all I want frozen is the first row: cells A1 to J1.

Before the above code is encountered, I clear out the first 1000 rows of the results sheet:

Sheet3.Range("A2:J1000").ClearContents

This is done to clear out the results from any previous searches.

Also, just before the freeze code, I have the following code:

Sheet3.Columns.AutoFit
Sheet3.Rows.AutoFit

This is done to reduce the area of the results sheet as much as possible.

Any ideas? Any help is greatly appreciated.
--
JJFJR
 
Code:
Sub s()
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Range("A2").Select
ActiveWindow.FreezePanes = True
End Sub
works fine with me

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top