[VBA] IF Statement

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi team,

I would like to add CODE_1 in front of CODE_2 but not sure how to do it.

It has to be merged into one macro, under the Private Sub Worksheet_Change(ByVal Target As Range)

VBA Code:
'CODE_1
If ThisWorkbook.Name = "NAME.xlsm" Then
run CODE_2
Else
Exit Sub
End If

VBA Code:
'CODE_2
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$1" Then
With Application
.ScreenUpdating = False
With Worksheets("ABC")
.Unprotect "PASSWORD123"
Call FILTER
Call ADD_DROP_DOWN_LIST
.protect "PASSWORD123"
End With
.ScreenUpdating = True
End With
End If
End Sub

TY for help!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hello. I assume that your Worksheet("ABC").Range("F1") is unlocked. Otherwise you won't be able to trigger the code.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If ThisWorkbook.Name = "NAME.xlsm" Then
        If Target.Address = "$F$1" Then
            With Application
                .ScreenUpdating = False
                With Worksheets("ABC")
                    .Unprotect "PASSWORD123"
                    Call Filter
                    Call ADD_DROP_DOWN_LIST
                    .Protect "PASSWORD123"
                End With
                .ScreenUpdating = True
            End With
        End If
    Else
        Exit Sub
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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