Houston Seminar in Excel VBA Macros
Excel VBA Macro to display the content
of a header row.
Sergio Perez Rodriguez
EG, PDG, MSc
April 2020
A macro to display the content in the cells of a header row can be setup as follows:
Sub MacroHead()
‘Definition of the variables
Dim he as Range
Dim v, ch as Integer
‘Selection of the header row and its assignment to the Range variable
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Set he = Selection
‘Assignment to an integer variable of the number of cells in the header row
ch = he.Columns.Count
‘Loop to display the content in the cells of the header row
For v = 1 To ch
MsgBox "Header " & v & " is " & he(1, v)
Next v
End Sub
Bibliography
Jelen, B., Syrstad, T. 2016. Excel 2016 VBA and Macros. Pearson Education.