The code doesn't seem to match the Excel formula. In the code, you are doing two separate mods, in the Excel formula, you are doing only one mod.

Setting that aside, as I guessed, there is an order of operations issue.

With the Excel formula, this is the order things are happening:

1. The value in B2 is squared
2. That result is divided by the value in B3
3. That result is then taken MOD of the value in B4

In the VBA code you posted, the MOD is happening at step 2, and step 3 is the division. That is why you are seeing different results. The power being an integer or not is not the issue based on what you have posted.