UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Display value in cell thru VBA    
 
   
AchyBreakyHeart
post Mar 2 2005, 02:12 AM
Post #1

UtterAccess Addict
Posts: 229
From: SG



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
Go to the top of the page
 
+
KingMartin
post Mar 2 2005, 03:02 AM
Post #2

Retired Moderator
Posts: 10,959
From: Prague,CZ / Kiev,UA



Hi Jamie,

'display'? Where?

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


Martin
Go to the top of the page
 
+
AchyBreakyHeart
post Mar 2 2005, 03:10 AM
Post #3

UtterAccess Addict
Posts: 229
From: SG



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
Go to the top of the page
 
+
NateO
post Mar 2 2005, 10:51 AM
Post #4

Remembered
Posts: 5,055
From: Minneapolis, MN, USA



Declare your variables as Double or Currency. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/wink.gif)
Go to the top of the page
 
+
AchyBreakyHeart
post Mar 2 2005, 10:07 PM
Post #5

UtterAccess Addict
Posts: 229
From: SG



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
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 01:15 PM