+ Reply to Thread
Results 1 to 6 of 6

Run multiple if statements

Hybrid View

rlh Run multiple if statements 02-28-2014, 07:30 PM
protonLeah Re: Run multiple if statements 02-28-2014, 08:08 PM
ajryan88 Re: Run multiple if statements 02-28-2014, 08:11 PM
rlh Re: Run multiple if statements 02-28-2014, 09:07 PM
rlh Re: Run multiple if statements 02-28-2014, 09:05 PM
ajryan88 Re: Run multiple if statements 02-28-2014, 09:20 PM
  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    NE
    MS-Off Ver
    2013
    Posts
    42

    Run multiple if statements

    What I am trying to do is run the code below for the same worksheet.

    The problem is Excel will only allow me to run one or the other.

    I want them to work at the same time.


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A1:A5")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    Target.Value = UCase(Target.Value)
    Application.EnableEvents = True
    
    If Intersect(Target, Range("B1:B5")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    Target.Value = Application.Proper(Target.Value)
    Application.EnableEvents = True
    End Sub
    Any help is greatly appreciated

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,937

    Re: Run multiple if statements

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub
        If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
            Application.EnableEvents = False
            Target.Value = UCase(Target.Value)
            Application.EnableEvents = True
        ElseIf Not Intersect(Target, Range("B1:B5")) Is Nothing Then
            Application.EnableEvents = False
            Target.Value = Application.Proper(Target.Value)
            Application.EnableEvents = True
        End If
    End Sub
    Ben Van Johnson

  3. #3
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Run multiple if statements

    Hi,

    Firstly, could you please indent your code in the future, it makes it a lot easier to read. Secondly, just remove the Exit Sub statements, and reverse the polarity of the If...Then statements, like this:
    Private Sub Worksheet_Change(ByVal Target As Range)
    	If Not Intersect(Target, Range("A1:A5")) Is Nothing And Target.Cells.Count <= 1 Then
    		Application.EnableEvents = False
    		Target.Value = UCase(Target.Value)
    		Application.EnableEvents = True
    	End If
    	
    	If Not Intersect(Target, Range("B1:B5")) Is Nothing And Target.Cells.Count <= 1 Then
    		Application.EnableEvents = False
    		Target.Value = Application.Proper(Target.Value)
    		Application.EnableEvents = True
    	End If
    End Sub
    Please note, I haven't tested this, I have done it off the top of my head. So please let me know if it still doesn't do what you're looking for and I'll take another look at it.

    I hope this helps

  4. #4
    Registered User
    Join Date
    08-21-2013
    Location
    NE
    MS-Off Ver
    2013
    Posts
    42

    Re: Run multiple if statements

    Thank you very much. This worked perfectly.

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    NE
    MS-Off Ver
    2013
    Posts
    42

    Re: Run multiple if statements

    Thank you protonleah. That worked perfectly.

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Run multiple if statements

    Please don't forget to mark this thread as solved

+ 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. Formula with multiple IF statements and IF AND statements
    By lottidotti in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-14-2013, 08:03 AM
  2. Replies: 3
    Last Post: 07-25-2013, 08:25 AM
  3. [SOLVED] Syntax for formula that uses multiple conditions inside of multiple IF statements
    By njmiller31 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-02-2013, 11:55 AM
  4. Multiple nested IF statements and AND statements
    By TonyGetz in forum Excel General
    Replies: 2
    Last Post: 12-14-2010, 03:07 AM
  5. Replies: 12
    Last Post: 05-15-2009, 08:38 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