Link to home
Start Free TrialLog in
Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on

Retriving cell value with VB

Folks,
In my worksheet I have this formula =Round(B7/C7,2) in cell D7. Hopefully, it will return a value ###.## or a two place decimal.
If that's the case I now need code that compares that value to another value. So if D7 is 14.56 and I compare in my code 14.60 I can then let the user know that their formula is wrong.
Avatar of Ken Butters
Ken Butters
Flag of United States of America image

Not clear what you want to do.

you said you want to let the user know their formula is wrong.  How do you want to let them know?

is the value 14.60 a constant value or is it a value that is derived from somewhere else on this sheet or a different one?

A couple of ways to let the user know...

You could do this in VBA code with a message box that pops up.

You could also do this with conditional highlighting.  -- This could color the cell or the text a different color if it doesn't match 14.60.
@buttersk

This is an extension of an ongoing question.  See if this additional info helps.
ASKER CERTIFIED SOLUTION
Avatar of Steven Harris
Steven Harris
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Changed my mind on this one. Still working.
Avatar of Frank Freese

ASKER

In regards to informing the user my sub-routine would looks something like this:
If the value in a cell does not equal what it should then I call a routine from a module that has a msgbox.
ThinkSpaceSolutions:
If I used in my formula Round(B2/B7*100,2) would the .Value work?
The .text worked.

Range("A1").Value sees "12.146999"; while
Range("A1").Text sees "12.15"

It appears I'll use the solution you provided but just wanted to know a little bit more about using the round function for value.

I'll go ahead and award the points - if you could addendum later I'd appreciate it.
thank you very much
If I used in my formula Round(B2/B7*100,2) would the .Value work?

Absolutely!  Since .Text is looking for the formatted data, whatever you see is what the VBA will see.
thanks - it is great to learn
Glad I could help!