Community Pick: Many members of our community have endorsed this article.
Excel macro for working with data files that have a header line - set up headings with filters and pane
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
IT consultant and specialist in WordPress website management
Published:
Updated:
Browse All Articles > Excel macro for working with data files that have a header line - set up headings with filters and pane
I regularly work with small to medium sized data files (.csv or other delimited text format) and find Excel the handiest tool for editing them. In my case, they usually have headings in the first line.
I created a handy macro to make the headings easier to read and the data easier to deal with by simply turning on the automatic data filter, freezing the headings in a separate pane, and resizing columns to match the data. Here's how to set it up yourself (Written for Excel 2003):
1. Raw text data loaded into Excel
Here's a csv file opened in Excel, unformatted:
2. The end result
Here's the end result. You can't see it here, but when you have more than a page of data, the headers stay visible at the top of the screen:
3. Creating the macro
To create the macro in Excel, we can't unfortunately easily copy and paste the code in, so we'll create an empty macro first:
Choose Tools -> Macro -> Record New Macro Enter the macro name "FormatHeadings", and choose a shortcut key (I like ctrl-h), and select to store the macro in "Personal Macro Workbook" (so that you can use the macro from any file you open), then click Ok A little pop up window will appear with a square stop button. Click the square stop button to stop the macro recording.Now we need to edit the macro to put our code in. To do this we need to first unhide the Personal Macro Workbook. Click Window -> Unhide Select PERSONAL.XLS and click Ok. You should now be in the Personal Macro Workbook "PERSONAL.XLS". Choose Tools -> Macro -> Macros. Select the macro you created from the list, and click Edit A "Microsoft Visual Basic" editing window should open, with your macro shown Replace all of the text between the "Sub ..." and "End Sub" lines (leave the sub and end sub lines themselves) with the following code:
Hit Ctrl-s or click the Save button to save your changes Close the "Microsoft Visual Basic" window.
Save the changes to your Personal Macro Workbook by clicking the Save button Choose Window -> Hide to hide your Personal Macro Workbook And you're set to go! Hit ctrl-h (or the shortcut you chose) to format your headings!
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Our community of experts have been thoroughly vetted for their expertise and industry experience. Experts with Gold status have received one of our highest-level Expert Awards, which recognize experts for their valuable contributions.
IT consultant and specialist in WordPress website management
Comments (0)