VBA code to calculate one number raised to the power another number i.e x to the power n

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

any help is appreciated

smileypkr · Sep 29, 2009 12:24 PM · 15,672 views

3 Replies

http://www.excelfunctions.net/... Operator Action Precedence (1=top; 5=bottom) ^ The power operator 1 * The multiplication operator 2 / The division operator 2 \ The integer division operator - this operator divides two numbers and returns the integer result (eg. 7\4 gives a result of 1) 3 Mod The modulus operator - this operator divides two numbers and returns the remainder (eg. 8 Mod 3 gives a result of 2) 4 + The addition operator 5 - The subtraction operator 5

techGuy · Sep 29, 2009 1:09 PM

Private Sub Power()   Dim val1 as double; //val1 is x   Dim val2 as double; //val2 is n   Dim val3 as double;  //val3 to store result   val3 = val1 ^ val2;  //val3 will have the result End Sub

xcopsgen · Sep 29, 2009 3:40 PM

scopsgen, U might want to declare the power as function taking two parameters val1, val2 and returning val3, the code is not of any use if you can not give argument or get value. right?? smileypkr, Why do you need VBA for power, you have power function in Excel  right, but if you want to use this in code makes sense, but you can always access inbuil power function using worksheetfunction property such as =Application.WorksheetFunction.Power(x,y)

shivanagar · Sep 29, 2009 5:08 PM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion