+ Reply to Thread
Results 1 to 5 of 5

Syntax error in calculations in Userform

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Hallettsville Texas USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Syntax error in calculations in Userform

    Ladies, Gentlemen,
    Further to my earlier post re "Calculating in a Userform" which was speedily resolved by Norie I thought to be smart and use the "change" event of the combo-box instead of the command-button to trigger some more calculations, as the value of the combo-box is common to both formulas.
    However, while running the code I was -unpleasantly- surprised by a VBA messagebox stating "Run-time Error 13" - Type Mismatch.
    An intensive search on the Net gave me a wealth of information but not what I was looking for to solve this problem.
    Therefore I went into the debug mode and when my mouse hovered over the cboSchaal.Value(3.5) in t6he second calculation it showed "Type mismatch" and the code stopped running.
    I am aware that cboSchaal.Value is quite different from
    cboSchaal.Value(3.5), hence the error.
    The formula however requires the value of the combo-box be raised to the power 3.5 in order to calculate the power required for the modelship.
    The formula itself is correct (tested in a worksheet) and the answer should be 8.86 Watts (based on scale 1:24)
    Therefore I think I make a mistake in the syntax of the formula, but which one ? Again searched the Net for some time, to no avail. Any suggestions will be very much appreciated as I am relatively new to VBA and learning as I go along. Have tried various variables (DIM, Static, Public and so on) but wasn't succesful. Looking forward to your suggestions, thanks in advance....
    P.S. Underneath the userform and the associated code.

    userform2.jpg

    Please Login or Register  to view this content.
    Best regards, Dirk Smit

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,090

    Re: Syntax error in calculations in Userform

    Guessing you need this: https://msdn.microsoft.com/en-us/lib...or=-2147217396
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Syntax error in calculations in Userform

    To raise to a power you use the ^ operator.

    So your code would become this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    04-03-2012
    Location
    Hallettsville Texas USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Syntax error in calculations in Userform

    Gents,
    A thousand thanks, all working fine. I must have overlooked the ^ operator with eyes going square from looking at the screen trying to find a solution.
    Sorry for the hardships I may have caused

    Dirk

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,090

    Re: Syntax error in calculations in Userform

    You're welcome. Thanks for the rep.

    No hardship at all; glad to have helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA userform problem with code (syntax error)
    By Odowd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-27-2016, 09:23 PM
  2. [SOLVED] Userform Textbox calculations divide by zero error
    By Code Flunkie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-27-2014, 11:15 AM
  3. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  4. [SOLVED] first timer using VB to cut and paste macro - getting compile error syntax error
    By jopedder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2013, 11:45 AM
  5. Receiving following error “Complie error : syntax error” Help
    By masond3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2012, 10:19 AM
  6. Syntax for returning Optionbutton (Userform) caption (Error 438 with ctr.value)
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-02-2011, 11:25 AM
  7. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM

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