OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Need help with simple macro in Calc

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
steeeeevo
General User
General User


Joined: 29 Aug 2009
Posts: 5

PostPosted: Sat Aug 29, 2009 10:08 pm    Post subject: Need help with simple macro in Calc Reply with quote

I have a formula for sales tax. If the result is less than zero, I want a message to pop up and notify me that we have an invalid sale.

The validate thing only works for data I enter, not date entered by a formula. Can anyone tell me how to make my pop up dreams come true?

I know the asnwer has to be with a macro somehow, but I really don't know my stuff and could use your help. THANKS!
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Sun Aug 30, 2009 8:57 am    Post subject: Reply with quote

How about a formula in the sales tax cell(s) for less than or equal zero.
=IF(A1*0.06<=0;"INVALID";A1*0.06)
Back to top
View user's profile Send private message
steeeeevo
General User
General User


Joined: 29 Aug 2009
Posts: 5

PostPosted: Sun Aug 30, 2009 3:00 pm    Post subject: Reply with quote

That's essentially what I have set up now, but I'd love for it to actually pop up a message on the screen that requires user input so that it forces the user's attention to be drawn to the issue. Thanks for any additional help.
Back to top
View user's profile Send private message
keme
Moderator
Moderator


Joined: 30 Aug 2004
Posts: 2910
Location: Egersund, Norway

PostPosted: Thu Sep 03, 2009 12:04 am    Post subject: Reply with quote

AFAIK it's possible to enable a "cell listener", but I don't know how to do that. A workaround when it's a formula is to write a function that returns a "safe" result (zero), then insert that in your formula.

Enter the following function in an OOo basic module:
Code:
function Notify(Notification as string)

' Give the notification
MsgBox(Notification,16,"Bad value")

' return a "safe" value from this function
Notify=0

End function

Append this to your formula: +IF(CURRENT()<0;Notify("The result is invalid."))

This will give a notification at each recalculation, so in some cases you may want to turn automatic recalculation off...
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Thu Sep 03, 2009 5:51 am    Post subject: Reply with quote

Data>Validity...
Allow decimal >= 0
Error alert: Show error message
Action: Stop (reject)

Unless you don't specify something else, the default message is "Invalid value" in the respective GUI language.
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
steeeeevo
General User
General User


Joined: 29 Aug 2009
Posts: 5

PostPosted: Sat Sep 05, 2009 7:31 am    Post subject: Reply with quote

Works great. Thanks Keme! I knew there had to be a way. Thanks for your help!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group