Full Version: Display value in cell thru VBA
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
AchyBreakyHeart
Hi,

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??

Jamie
KingMartin
Hi Jamie,

'display'? Where?

CODE
MsgBox "Content of cell A1 is... " & Range("A1").value


Martin
AchyBreakyHeart
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
Next d

Range("D" & i).End(xlUp)(2) = total
</pre><hr />

'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?

Jamie
NateO
Declare your variables as Double or Currency. wink.gif
AchyBreakyHeart
Thanks thanks..

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..

Jamie
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.