The following tex file is trying to set a text (in this case a number, but it could be a string as well) in the footer of one page and the same value in the header on the following page. The idea is to set the value needed in the footer with each data item, then after each page update the header value for the following page.
The footer works ok, the header does not. The value in the header on the first page is ok, the value on the following pages are not.
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{afterpage}
\author{Bent Nielsen}
\title{page change testing}
\gdef\Total{0.00}
\gdef\TopTotal{0.00}
\afterpage{\gdef\TopTotal{\Total}}
\pagestyle{fancy}
\fancyhf{}
\rhead{Top Total \TopTotal }
\rfoot{Current total \Total}
\begin{document}
Page 1
\gdef\Total{5.00}
\gdef\Total{10.00}
\gdef\Total{15.00}
\newpage
Page 2
\gdef\Total{20.00}
\gdef\Total{25.00}
\gdef\Total{30.00}
\newpage
Page 3
\gdef\Total{35.00}
\gdef\Total{40.00}
\gdef\Total{45.00}
\end{document}