• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combine two VBA codes as one.

Kabasa007

New Member
Hi all,

I am new to VBA and Macros.

I have two VBA codes that are triggered when an event occurs in my worksheet and want to combine them as one.
Now the problem is i dont know what structure it should take or what line to add/join the second code with the first code on the code window.

I use Office 365. I have attached the sample file which has the first code in the VBA window. The second code is pasted below.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Sheet2.Unprotect "123"

If VBA.IsEmpty(Target) Then
    Target.Locked = False
    Else
    Target.Locked = True
End If

Sheet2.Protect "123"

End Sub

Please help.
 

Attachments

  • Sample File.xlsm
    20.1 KB · Views: 7
Why are you specifying Sheet2 in your 2nd code to combine? I don't see Sheet2 in your sample.

What is it exactly that you are trying to do here?
 
That was an error. Replace it with "sheet1". I am trying to combine the two codes in a way that they can both work in the same work sheet.
 
Last edited by a moderator:
Back
Top