VBA Question

N

Nick

I am trying to create a variable that returns the result
of a formula within a cell in my excel file. The code
I've tried is:

ASMETERS = Sheets("Sheet3").Range("b2")

The result I get is the actual formula within that cell,
but I would like it give me the results of the formula.

Thanks for any advice available.
 
J

Jim Rech

You should explicitly state what you want. E.g.,

ASMETERS = Sheets("Sheet3").Range("b2").Value

ASMETERS = Sheets("Sheet3").Range("b2").Formula
 
G

greg

try
asmeters = Sheets("Sheet3").Range("b2").Value

to check use
Msgbox asmeters

Regards,
Greg
 
B

Bob Phillips

Value is the default property for Range, so if no property is stated, Value
is assumed. When I do
?Range("I1")
and I1 has the formula
=SUMPRODUCT((A1:A3=DATE(2003,10,31))*(B1:B3="Chris Grider"),C1:C3)
it reruns the formula result, which is 10.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
J

Jim Rech

I never depend on getting the default property. I always spell it out.
I've seen rare cases where it goes wrong. Just my personal style, fwiw (not
much<g>).
 
B

Bob Phillips

I agree with that Jim, but I don't think it is the OP's problem because it
is the default.

Bob
 
J

Jim Rech

Well, I'm thinking this might be one of those cases where the default, for
whatever reason, doesn't do what it should. As I said, the reason I do not
rely on the default is because I have seen it not work as it should. This
could be one of those cases. Only the OP can tell us.
 
Top