+ Reply to Thread
Results 1 to 7 of 7

Inequality in Excel (VBA)

  1. #1
    Forum Contributor
    Join Date
    02-21-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    100

    Inequality in Excel (VBA)

    Hi everyone!

    Need some help with some VBA Code.

    The idea is:

    Theres a New product form. It allows someone to create a new product by filling in 3 fields. Product Description, Cost Price, and Selling Price.

    Ive got the VBA Code working fine, and it adds the product succesfully in a sheet.

    What I want to do now:

    I want to futher improve this VBA Code, by putting in an inequality. Basically, I want the form to check that the Selling Price is greater than the Cost Price - (obviously!, if not theres no profit).

    So basically, if someone puts in a selling price which is less than the cost price, the system throws up an error box saying the selling price is lower than the cost price.

    Its pretty simple I think - I got something similar done but it didnt quite work well.

    Thanks!
    Last edited by excelit; 03-06-2011 at 08:19 AM.

  2. #2
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: Inequality in Excel (VBA)

    Hi

    For your enter button try the following, for textboxes - tbsell and tbcost (amend accordingly):

    Please Login or Register  to view this content.
    Will throw up message boxes if there is either a value missing or sell is less than cost and return to the form for amendment.

    Regards

    Jeff

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Inequality in Excel (VBA)

    Think you need to convert those text values to numbers first, Jeff, otherwise "123" < "45"
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    02-21-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    100

    Re: Inequality in Excel (VBA)

    @ Jeff

    EDIT: Got it working with numbers only

    Works - but yeh, I need to format the selling price and cost price field as numbers..if not It lets me put in "test" as the cost price of the product :P

    I checked the properties of the field and got nothing..is it something in VB i have to add?
    Last edited by excelit; 03-03-2011 at 05:37 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Inequality in Excel (VBA)

    Please don't quote whole posts.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-21-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    100

    Re: Inequality in Excel (VBA)

    Hello,

    I tried your code @shg - but theres a problem.

    After the msgbox comes up saying "Fix cost", the values are still added in the worksheet.
    The code I have after yours basically adds the data filled in the form onto two sheets, but if any of the if conditions are met in your code, i want the rest of the code to stop running.

    How do I do that?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Inequality in Excel (VBA)

    Put Exit Sub after each MsgBox.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1