Combining multiple VB Codes

EBoudreau

Board Regular
Joined
Aug 21, 2015
Messages
153
I am in need of getting these two codes to work together on the same worksheet.

Any ideas? I've tried several tactics from searching online but i'm missing something somewhere.

The two codes I have are:

Private Sub Worksheet_Change(ByVal Target As Range)




On Error GoTo myerror
If Not (Application.Intersect(Target, Range("E8:CQ19, E22:CQ33, E36:CQ47")) Is Nothing) Then
Application.EnableEvents = False
With Target
If (Not .HasFormula) And (.Count = 1) Then Target = UCase(Target.Cells(1))
End With
End If




myerror:
Application.EnableEvents = True
End Sub


and


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address <> "$E$5" Then Exit Sub
Application.EnableEvents = False
MsgBox "I Don't Think So!",
48, "Sorry, I'm protected."
Application.Undo
Application.EnableEvents = True
End Sub


What can i do??
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try something like this...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    On Error GoTo myerror
    
    If Not Intersect(Target, Range("E8:CQ19, E22:CQ33, E36:CQ47")) Is Nothing Then
        Application.EnableEvents = False
        With Target
            If (Not .HasFormula) And (.Count = 1) Then .Value = UCase(.Cells(1))
        End With
    ElseIf Target.Address = "$E$5" Then
        Application.EnableEvents = False
        MsgBox "I Don't Think So!", 48, "Sorry, I'm protected."
        Application.Undo
    End If
        
myerror:
    Application.EnableEvents = True
    If Err.Number <> 0 Then MsgBox Err.Description, vbCritical, "Error " & Err.Number
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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