[Tex/LaTex] fancyhdr and lastpage: do not count last page

fancyhdrlastpage

I am using fancyhdr and lastpage.
I want to write a Bachlorthesis and the last page must be the statutory declaration wich should not be part of the page count. But this page is counted in LastPage. How can i get lastpage to not count this page ?

\setcounter{page}{\pageref*{LastPage}-1} is what i am looking for

\documentclass[a4paper]{report}

\usepackage{fancyhdr}
\usepackage{lastpage}

\pagestyle{fancy}
\fancypagestyle{plain}{}
\fancyhead[RO,RE]{Page \thepage\ of \pageref*{LastPage}}
\fancyhead[LO,LE]{\leftmark}

\begin{document}

% much content

% now the last page:
\thispagestyle{empty}
% content of the declaration

Best Answer

You can use the zref package and decrease the generated number by 1.

\documentclass[a4paper,twoside]{report}

\usepackage{fancyhdr}
\usepackage[lastpage]{zref}

\usepackage{kantlipsum}

\makeatletter
\newcommand{\reallastpage}{%
  \the\numexpr\zref@extractdefault{LastPage}{page}{0}-1\relax
}
\makeatother
\pagestyle{fancy}
\fancypagestyle{plain}{}
\fancyhead[RO,RE]{Page \thepage\ of \reallastpage}
\fancyhead[LO,LE]{\leftmark}

\begin{document}

\kant

% now the last page:

\clearpage
\thispagestyle{empty}

{\Large Declaration}

\kant[1]

\end{document}

enter image description here

As you can see, the declaration page is number 4.