Run multiple VBA codes for 1 spreadsheet.

Angel7

New Member
Joined
Mar 30, 2011
Messages
2
How do you combine the following 2 VBA code for the same spreadsheet:

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect "123"
Target.Locked = True
ActiveSheet.Protect "123"
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
With Cell
If .Column = 1 Then
Cells(.Row, 2).Value = Date '+ Time
End If
End With
Next Cell
End Sub
 

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".
What is it that you're trying to do?
'm not sure what are you trying to achieve but try this
Code:
[/FONT]
[FONT=Courier New]Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
With Cell
If .Column = 1 Then[/FONT]
[FONT=Courier New]Application.EnableEvents = False
ActiveSheet.Unprotect "123"
Cells(.Row, 2).Value = Date '+ Time
Cells(.Row, 2).Locked = True
ActiveSheet.Protect "123"[/FONT]
[FONT=Courier New]Application.EnableEvents = True
End If
End With
Next Cell
End Sub
 
Upvote 0
I appreciate your help with this.

My goal is to Auto Lock cells after data entry and to Auto enter a date as well.

The formula you supplied works only for the Auto date entry not the Auto Lock.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

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