So I am trying to split an array into two halves and am having allot more trouble than I anticipated. Setting break points, I know that as these lines are being executed "sz"(Integer) is set to 9. This code sets "rightSz"(Integer) to be 4, which is what I expected, but it also sets "leftSz"(Integer) to be equal to 6. I have no idea why it is giving me this and it is causing a lot of problems in later sections of my code.
If sz Mod 2 = 1 Then
rightSz = sz / 2
leftSz = rightSz + 1
Else
leftSz = sz / 2
rightSz = sz / 2
End If
Here is another approach, using the
Int()
function to round down half of the original number to a whole number. The other half is calculated by computing the difference from the original. Might be slightly less confusing if people are not as familiar withMod
.Also note that
/
is not the same as\
when it comes to division in VBA. The forward slash returns the fraction, while the backslash returns a whole number. Using this concept, you could use the backslash instead of theInt()
function to yield the same result.