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.
Frank FreeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ken ButtersCommented:
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.
0
Steven HarrisPresidentCommented:
@buttersk

This is an extension of an ongoing question.  See if this additional info helps.
0
Steven HarrisPresidentCommented:
In short, I had to sit down and think after a long day...

To return the formatted text from a cell in VBA, you would use Range.Text

For example-

If A1 has the raw value "12.146999" and is formatted to "00.00" format, then:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

FaustulusCommented:
Changed my mind on this one. Still working.
0
Frank FreeseAuthor Commented:
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.
0
Frank FreeseAuthor Commented:
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.
0
Frank FreeseAuthor Commented:
thank you very much
0
Steven HarrisPresidentCommented:
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.
0
Frank FreeseAuthor Commented:
thanks - it is great to learn
0
Steven HarrisPresidentCommented:
Glad I could help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.