+ Reply to Thread
Results 1 to 15 of 15

vba compile error elseif

  1. #1
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Cool vba compile error elseif

    this is my code snippet, when it runs I get a compile error "else without if" I don't understand what I have done incorrectly could anyone assist me please
    Please Login or Register  to view this content.
    Last edited by royUK; 12-11-2011 at 01:51 PM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: vba compile error elseif

    You are missing a "End if" statement after the last "Else" statement.

    When posting code you need to add code tags around it.
    You can read about it in the forum rules.
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: vba compile error elseif

    Sorry I missed the quotes. I've tried it with the "end if" between the last "else" but I still get the compile error, I've also tried it after "next cell" with the same result Have I put it in the wrong place?

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: vba compile error elseif

    Remove the colon in this line

    Please Login or Register  to view this content.

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

    Re: vba compile error elseif

    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

    Added this time

    A Select Case is much easier to follow

    Please Login or Register  to view this content.
    Last edited by royUK; 12-11-2011 at 01:56 PM.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Cool Re: vba compile error elseif

    Hi thank you for your assistance. what I'm trying to do is add a value to a cell if its current value is less than or equal to a predetermined value, then once the static amount is set to multiply all cells by 30% and round to 2 decimal places.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: vba compile error elseif

    hi UKTV2C, this sets a cell value equal to cell value + 30% of this cell value rounded to 2 decimal points

  8. #8
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Cool Re: vba compile error elseif

    Okay so I have the code correct, but where in the main body of code does it go in order for it to carry out it's function? Thank you all.

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

    Re: vba compile error elseif

    You've posted part of the codem we can't see where the it is from or where to place it. My code replaces your IF & ElseIf lines

  10. #10
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: vba compile error elseif

    Here it is again the whole snippet which is bringing up the compile error, could you please re write it for me so that it would work, my skills are obviously lacking. Thank you


    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: vba compile error elseif

    Hi Roy I have pasted the code almost a week ago, you were very kind then, I just have not understood. Would you be kind enough to adjust the code please so that if performs each action as required then performs the last function which is to multiply by 32% and round to two places. thanks in anticipation of your assistance.

  12. #12
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: vba compile error elseif

    Hi Roy I have pasted the code almost a week ago, you were very kind then, I just have not understood. Would you be kind enough to adjust the code please so that if performs each action as required then performs the last function which is to multiply by 32% and round to two places. thanks in anticipation of your assistance.

  13. #13
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: vba compile error elseif

    Try this:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: vba compile error elseif

    Thanks so much for your help, yes it works on the correct file when I have the macro spreadsheet open testing. When I close it and use the VBA script to run it ti does not perform the function on the fie I want it to. I will have it wrong as I started our recording this Macro.

    This is what I have to say which file to apply the macro to could you advise please?

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    12-11-2011
    Location
    suderland england
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: vba compile error elseif

    Hi Stephen I've worked it out thanks for all the assistance from all of you.

+ 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