+ Reply to Thread
Results 1 to 9 of 9

Multiple If Statements in VBA

  1. #1
    Registered User
    Join Date
    09-17-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    21

    Multiple If Statements in VBA

    I am having a hard time making this macro work. It won't let me use the elseif statement. Any suggestions would be appreciated.

    Please Login or Register  to view this content.
    Last edited by JoseK70; 01-12-2012 at 12:33 PM.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Multiple If Statements in VBA

    Just a heads up, forum rules require you to put any VBA code in between code tags. For example
    Please Login or Register  to view this content.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Multiple If Statements in VBA

    Hi JoseK70,

    Your problem looks like you need a SELECT CASE statement to make it easier. If you use the "TO" range in a CASE statement, I think it will do what you want.

    See http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx or
    http://support.microsoft.com/kb/213630
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    09-17-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Multiple If Statements in VBA

    Thanks for the help. I have one more question. Instead of making my variable LOne an Integer how do I keep it as a decimal? Because when it compares to my sheet it turns LOne into 1 instead of .8.

    Thanks.

  5. #5
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Multiple If Statements in VBA

    Try changing the dimension of the variable:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-17-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Multiple If Statements in VBA

    Thanks for all the help this is what the final code looks like

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Multiple If Statements in VBA

    I was thinking of SELECT statement too; it will make whoever is editing the code a lot easier to update.

  8. #8
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Multiple If Statements in VBA

    I modified the code

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Multiple If Statements in VBA

    Ignore the last post. Typed too fast.

    Please Login or Register  to view this content.

+ 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