ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Create a Header Row (https://www.excelbanter.com/excel-programming/351670-how-create-header-row.html)

DevDaniel

How to Create a Header Row
 
I have a set of data without headers. I want to programmatically insert a
blank row into Row 1, then add a header (e.g., the column letter) for each
column in the data range.

Jim Thomlinson[_5_]

How to Create a Header Row
 
You can just record a macro to do that, unless there is more to what you want
than what you have described...
--
HTH...

Jim Thomlinson


"DevDaniel" wrote:

I have a set of data without headers. I want to programmatically insert a
blank row into Row 1, then add a header (e.g., the column letter) for each
column in the data range.


Kevin B

How to Create a Header Row
 
You can tell Excel to print row and column heading directly from File/Page
Setup. Click on the Sheet tab of the Page Setup dialog box and locate the
check box in the print panel about mid page.
--
Kevin Backmann


"DevDaniel" wrote:

I have a set of data without headers. I want to programmatically insert a
blank row into Row 1, then add a header (e.g., the column letter) for each
column in the data range.


Kevin B

How to Create a Header Row
 
If you don't want the row numbers you can run this code instead:

Sub ColumnHeadings()

Dim varVal As Variant
Dim strAddress As String
ActiveSheet.Range("A1").Select
ActiveCell.EntireRow.Insert
varVal = ActiveCell.Offset(1).Value

Do Until varVal = ""
strAddress = Application.ConvertFormula( _
"R" & ActiveCell.Row & "C" & ActiveCell.Column, _
xlR1C1, xlA1, xlRelative)
If Len(strAddress) = 3 Then
strAddress = Left$(strAddress, 2)
Else
strAddress = Left$(strAddress, 1)
End If
ActiveCell.Value = strAddress
ActiveCell.Offset(0, 1).Select
varVal = ActiveCell.Offset(1).Value
Loop

End Sub

--
Kevin Backmann


"DevDaniel" wrote:

I have a set of data without headers. I want to programmatically insert a
blank row into Row 1, then add a header (e.g., the column letter) for each
column in the data range.


DevDaniel

How to Create a Header Row
 
It worked! Thanks for your help, Kevin. And thanks for taking the time to
consider my problem, Jim.
--
Dan

"Kevin B" wrote:

If you don't want the row numbers you can run this code instead:

Sub ColumnHeadings()

Dim varVal As Variant
Dim strAddress As String
ActiveSheet.Range("A1").Select
ActiveCell.EntireRow.Insert
varVal = ActiveCell.Offset(1).Value

Do Until varVal = ""
strAddress = Application.ConvertFormula( _
"R" & ActiveCell.Row & "C" & ActiveCell.Column, _
xlR1C1, xlA1, xlRelative)
If Len(strAddress) = 3 Then
strAddress = Left$(strAddress, 2)
Else
strAddress = Left$(strAddress, 1)
End If
ActiveCell.Value = strAddress
ActiveCell.Offset(0, 1).Select
varVal = ActiveCell.Offset(1).Value
Loop

End Sub

--
Kevin Backmann


"DevDaniel" wrote:

I have a set of data without headers. I want to programmatically insert a
blank row into Row 1, then add a header (e.g., the column letter) for each
column in the data range.



All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com