In this paper, we establish the formulas of the maximal and minimal ranks of the quaternion matrix expression C 4 - A 4 XB 4 where X is a variant quaternion matrix subject to quaternion matrix equations A 1 X = C 1 , XB 2 = C 2 , A 3 XB 3 = C 3 . As applications, we give a new necessary and sufficient condition for the existence of solutions to the system of matrix equations A 1 X = C 1 , XB 2 = C 2 , A 3 XB 3 = C 3 , A 4 XB 4 = C 4 , which was investigated by Wang [Q.W. Wang, A system of four matrix equations over von Neumann regular rings and its applications, Acta Math. Sin., 21(2) (2005) 323–334], by rank equalities. In addition, extremal ranks of the generalized Schur complement D - CA - B with respect to an inner inverse A − of A, which is a common solution to quaternion matrix equations A 1 X = C 1 , XB 2 = C 2 , are also considered. Some previous known results can be viewed as special cases of the results of this paper.