Help Combining 2 VBA Change codes

tylerstoehr

New Member
Joined
Aug 27, 2014
Messages
5
Hello,

I am trying to combine a couple of simple VBA Change codes but am unable to get both working at the same time. The one coded first works, the second doesn't.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


    With Target
        If Intersect(Target, Range("A:A,F:F")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
            Application.EnableEvents = False
            Target.Value = UCase(Target.Value) 'Sets range values to uppercase
            Application.EnableEvents = True
    End With
    
    With Target
        If Intersect(Target, Range("C:C")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
            Application.EnableEvents = False
            Target.Value = StrConv(Target.Value, vbProperCase) 'Sets range to proper case
            Application.EnableEvents = True
    End With
    






End Sub

Very simple, I am very new to this all help is greatly appreciated.

Thank you in advance!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
That's because you are telling it to Exit the Sub if the first condition is not met.
Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("A:A,F:F")) Is Nothing Then
        Application.EnableEvents = False
        Target.Value = UCase(Target.Value) 'Sets range values to uppercase
        Application.EnableEvents = True
    End If
    
    If Not Intersect(Target, Range("C:C")) Is Nothing Then
        Application.EnableEvents = False
        Target.Value = StrConv(Target.Value, vbProperCase) 'Sets range to proper case
        Application.EnableEvents = True
    End If

End Sub
 
Last edited:
Upvote 0
Ahhhhhh!

The old reverse of logic to allow passthrough. Thank you!

I was expecting a solution that used If ... Then goto X, but this solution is much more elegant!

THank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,685
Members
449,329
Latest member
tommyarra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top