Professional Documents
Culture Documents
Using A Formula in A Footer
Using A Formula in A Footer
Using A Formula in A Footer
With Worksheets("Sheet1")
' Set wording for date range
sTemp = .Range("E1").Text & " through " & .Range("E2").Text
sTemp = sTemp & " (" & .Range("E3").Text & ")"
.PageSetup.CenterFooter = sTemp
End With
End Sub
There are a few things to note in this macro. First of all, the macro only sets the footer
information in the worksheet named Sheet1, though you can change this worksheet name to
whatever you need. Second, notice that the .Text property is used instead of the .Value
property. There are actually three ways you could reference the cell contents, as shown here:
sTemp = Worksheets("Sheet1").Range("E1")
sTemp = Worksheets("Sheet1").Range("E1").Value
sTemp = Worksheets("Sheet1").Range("E1").Text
The first two approaches are equivalent; they set sTemp equal to the contents of the cell. The
third approach is different; it sets sTemp equal to the formatted text of the cell. In other
words, sTemp will be equal to whatever is in cell E1, as it is formatted in the cell. Since you
are working with dates and sums, this is the approach you want to use, so it is what was
used in the macro.
Third, the macro ends up setting up the footer in the sTemp variable. As written, the macro
would create a footer that looked similar to this:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (559)
applies to Microsoft Excel 2007, 2010, 2013, and 2016.