+ Reply to Thread
Results 1 to 7 of 7

VBA If else statement

  1. #1
    Registered User
    Join Date
    05-11-2010
    Location
    Portland oregon
    MS-Off Ver
    Excel 2007
    Posts
    10

    VBA If else statement

    Hi,
    I am trying to write a program for a user form which takes data from the user interface and calculates on the command click and I am trying to do using if else statements but something is wrong can any body help me with this. The code have written is below. I am a beginner and just started using VBA.

    Thanks

    Please Login or Register  to view this content.
    Last edited by peedarp1985; 05-14-2010 at 11:52 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA programming help

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: VBA If else statement

    I not sure that I understand what you're doing, but I'll try
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-11-2010
    Location
    Portland oregon
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA If else statement

    Thnak's for helping me out with this. Well I am trying to build a user form where it takes value from text box for size D and one for length L and I choose a process in a combobox like size, straightness, circularity and cylyindricity which have different formulas and are associated with each other. So when I enter a size and length and choose a process and hit the command button I want it to calculate the value. So D is a constant and ts, ci, cy are all results which I want to be able to calculate . I am not sure if you understand what i am trying to do? But i could use some assistance on this.

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: VBA If else statement

    The way you describe the process could easily be done on a spreadsheet without using a form.
    If you really want to do it on a form, can you give some examples of what you're looking for, like if the user enters 3 in size and 2 in length what will be the answer for each selection in the combobox?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA If else statement

    Hello peedarp1985,

    Your If Then statements are not working because the data being evaluated is a String and not a Number. All data going into and coming out of a TextBox is a String. You will need to convert the text to a number before you test it. It is easier to read using the Select Case statement rather than multiple If Then. Indent your code. It makes it easier to read and to correct.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-14-2010 at 09:35 PM. Reason: Changed Integers to Doubles in Dim statements
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    05-11-2010
    Location
    Portland oregon
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA If else statement

    Thanks guys I actually solved it. I just had to use double in place of integer which was a silly goof up. Thanks for the help and advice once again.

+ 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