Mar 2 2005, 02:12 AM
After working wif Access for so long, I'm trying my hand in Excel now.. HEE
Trying to display a value in a cell, how do i do that using VBA??
Mar 2 2005, 03:02 AM
MsgBox "Content of cell A1 is... " & Range("A1").value
Mar 2 2005, 03:10 AM
Displayed in the cell.. but its ok now.. I figured it out anyway.
but i have another tricky problem now. I'm trying to find the compound interest of a principle amount. I've already calculated out the interest rate paid over a few days and I want to add them together.
<font class="small">Code:</font><hr /><pre>
principle = Range("A" & i).Value
interest = Range("B" & i).Value
days = Range("C" & i).Value
For d = 1 To days
val = principle * interest
principle = principle + val
total = total + val
Range("D" & i).End(xlUp)(2) = total
'val' data type is Long and so is 'total'. but when i display total, the value becomes rounded up. Meaning the correct value inside of 'total' should be 78.8125 but when I display in the worksheet, the value has been rounded up to 79.
Even if i format the cells to display decimal places, it still shows 79.000.
any ideas how to fix this?
Mar 2 2005, 10:51 AM
Declare your variables as Double or Currency.
Mar 2 2005, 10:07 PM
But unfortunately it still didn't work.. sighz
Anyways i've solved it logically.
Instead of using a "total" variable to store the accumulated interest, I just stored the accumulated interest in "val" itself. In the end, I managed to get the figures I wanted with all the decimal places..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here