Why cells(1,1) = 500 * 100 causes overflow but 50000*100 doesn’t?

Consider:

Sub add()
    'This works:
    Cells(1, 1) = CLng(500) * 100
    'as does this:
    Cells(2, 2) = 50000 * 100
End Sub

Evidently VBA was picking a default type of Integer for the first expression because that type is large enough to hold the literals on the right hand side. 50000 is too big for an Integer so it interprets it as a Long. CLng explicitly triggers a promotion to Long.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)