+ Reply to Thread
Results 1 to 13 of 13

Multiple IF statements in VBA

  1. #1
    Registered User
    Join Date
    06-20-2012
    Location
    England
    MS-Off Ver
    Office 365 Excel
    Posts
    62

    Multiple IF statements in VBA

    Hey All,

    I am attempting to put multiple IF statements into a cell via VBA
    Reason for VBA: Cleanliness for my users, I dont want them messing around with Formulas etc plus the sheet that the formula is being entered into is massivly modified before this formula is put in via VBA - It is copied from another sheet, multiple rows deleted, multiple formats etc.

    I am attempting to set the following IF statements

    If any cell in Column E is equal to;
    How do I
    I need a Change
    I need Help
    I need help with Source IT
    Then enter the text "V" into the cell on the same row in Column G

    If Column E is equal to;
    OTHER
    Then put the text "O" into the cell on the same row in Column G

    If anything else leave blank.

    Please see attached outcome sheet.

    Any help is greatly appreciated!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    Hello there,

    I believe the following will work for you:

    Please Login or Register  to view this content.
    To use this code:

    1. Select the worksheet you want to have column G update automatically to a value
    2. Right click on the worksheet's tab
    3. Select the View Code option
    4. In the blank space provided copy and paste the above code, anything that appears in green is a comment meant to help you understand.
    5. Close out of the Visual Basic window. Go to column E and either enter a value or enter into a cell and press enter to accept the current value.
    6. The value in column G should update automatically.

    PLEASE NOTE: The Select Case statement is case sensitive so if the user doesn't type the values the way the appear in the statement the code will not work properly.

    Let me know if this works for you!

    Thanks!

  3. #3
    Registered User
    Join Date
    06-20-2012
    Location
    England
    MS-Off Ver
    Office 365 Excel
    Posts
    62

    Re: Multiple IF statements in VBA

    Thanks, Ill try this now!

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    Your welcome, if it works out for you please mark this thread Solved and maybe give a little star tap if I helped!

    Thanks!

  5. #5
    Registered User
    Join Date
    06-20-2012
    Location
    England
    MS-Off Ver
    Office 365 Excel
    Posts
    62

    Re: Multiple IF statements in VBA

    Rvasquez,

    Is there any chance you could change this so that I can just call on the sub during my current sub (instead of having to click into the cell and change the value, because at the moment it attempts to run right in the middle of my sub because the value is set on that cell and it messes up)

    Thanks ever so much for your time.

  6. #6
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    I'm sure I can, but I'm sorry I'm a little confused by what you mean by your current sub?
    Do you currently have a code that runs in the worksheet? If so, can you provide that and I can try and help.

    Thanks!

  7. #7
    Registered User
    Join Date
    06-20-2012
    Location
    England
    MS-Off Ver
    Office 365 Excel
    Posts
    62

    Re: Multiple IF statements in VBA

    Yeah here it is, its kinda big, and possibly messy - Because im really new to VB the Macro Recorder was used alot so the code is quite long but does the job perfectly in no time at all!

    But this one IF statement thing is getting me,.

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    Is this code in a Module or in the workbook?

  9. #9
    Registered User
    Join Date
    06-20-2012
    Location
    England
    MS-Off Ver
    Office 365 Excel
    Posts
    62

    Re: Multiple IF statements in VBA

    Module, activated by a button.

  10. #10
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    Okay lets try this, remove the code I gave you from the place you placed it in. Instead...

    1. After the End Sub of you Button2 macro copy and paste the below code

    Please Login or Register  to view this content.
    So your Module should look like:

    Please Login or Register  to view this content.
    2. In your Button2 macro you can call the AssignValToG macro by merely placing the text AssignValToG in the position you want the macro to start running. For example if you wanted the AssignValToG macro to run after the Button2 macro your code would look like this: (I've highlighted where it calls the macro)

  11. #11
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-20-2012
    Location
    England
    MS-Off Ver
    Office 365 Excel
    Posts
    62

    Re: Multiple IF statements in VBA

    Legend! Much appreciated mate, rep added.

    Finally finished my project, woop! - Had quite alot of help of guys here but feel I've learned quite a substantial amount more VB Coding, anything more than nothing is good!

    Thanks.

  13. #13
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Multiple IF statements in VBA

    Glad to hear you finished your project! Congratulations! Thanks for the star tap, much appreciated!

+ 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