VBA Tip: Square Root / Square
Square root
To get the square root of a VBA value, you need the Sqr function:
Sub example()
test_number = 9
MsgBox Sqr(test_number) 'Show the square root: 3
End Sub
Square
To get the square of a number, you can use "^" (as for a formula in a cell):
Sub example()
test_number = 9
MsgBox test_number ^ 2 'Show the square: 81
MsgBox test_number ^ 3 'Show the cube: 729
End Sub