Hello
Can someone help me in merging the below two VBA codes to into one VBA code.
Option Explicit
'Update 20140722
Private Sub Worksheet_Change(ByVal Target As Range) 'This will run always when a cell is changed it this sheet
Dim WorkRng As Range 'The Currently changed cell
Dim Rng As Range 'Helper range
Dim xOffsetColumn As Integer 'Integer of the needed offset
Set WorkRng = Intersect(ActiveSheet.Cells(Target.Column).EntireColumn, Target) 'Set workRng to changed cell
xOffsetColumn = 2
Select Case WorkRng.Column 'Depending on what column the changed cell is, change the offsetvalue (needed later in the code)
Case Is = 7
xOffsetColumn = 9
Case Is = 15
xOffsetColumn = 2
Case Is = 9
xOffsetColumn = 11
Case Is = 10
xOffsetColumn = 11
Case Is = 12
xOffsetColumn = 11
Case Is = 13
xOffsetColumn = 11
Case Else
xOffsetColumn = 0
End Select
If Not WorkRng Is Nothing And Not xOffsetColumn = 0 Then 'If workRange is not empty, and cell that we changed were field1 or 2
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 2 Then
confirm = MsgBox("Do you wish to confirm entry of this data?" _
& vbCrLf & "You will not be allowed to change it!", vbYesNo, "Confirm Entry")
Select Case confirm
Case Is = vbYes
Dim Cell As Range
With ActiveSheet
.Unprotect Password:="asdf,1234"
.Cells.Locked = False
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = "" Then
Cell.Locked = False
Else
Cell.Locked = True
End If
Next Cell
.Protect Password:="asdf,1234"
End With
Case Is = vbNo
Application.Undo
End Select
End If
Application.EnableEvents = True
End Sub
Bookmarks