Merge 2 VBA code help

Jagat Pavasia

Active Member
Joined
Mar 9, 2015
Messages
406
Office Version
  1. 2021
Platform
  1. Windows
Dear sir, I have 2 VBA code,
Please Help me to Merge it, so that I will not get Error.

VBA code is Below


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Intersect(Target, Range("D7:J2500 ,L7:M2500")) Is Nothing Then Exit Sub
    Select Case Target.Column
        Case 4 To 10
            If Target <> "" Then
                With Target.Offset(, 14)
                    .Value = Now()
                    .NumberFormat = "dd/mm/yy  hh:mm AM/PM"
                End With
            Else
                Target.Offset(, 14).ClearContents
            End If
        Case Is = 12, 13
            If Target <> "" Then
                With Target.Offset(, 13)
                    .Value = Now()
                    .NumberFormat = "dd/mm/yy  hh:mm AM/PM"
                End With
            Else
                 Target.Offset(, 13).ClearContents
            End If
    End Select
    Application.ScreenUpdating = False
End Sub


ANOTHER VBA IS BELOW :

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
 
  If Target.Count > 1 Then Exit Sub
  Application.EnableEvents = False
  ActiveSheet.Unprotect
  Set rng = Range("q:q")
  If Not Intersect(Target, rng) Is Nothing Then
    If Target.Value = "**" Then Target.Value = Format(Date, "mm/dd/yyyy")
  End If

  If Not Intersect(Target, Range("A5:O5")) Is Nothing Then
      If Target.Value = "" Then
          ActiveSheet.Range("A7:O7").AutoFilter Field:=Target.Column
      Else
          ActiveSheet.Range("A7:O7").AutoFilter Field:=Target.Column, Operator:=xlFilterValues, Criteria1:=CStr(Target.Value)
      End If
  End If
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFiltering:=True
  Application.EnableEvents = True
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
 
  If Target.Count > 1 Then Exit Sub
  
  Application.EnableEvents = False
  ActiveSheet.Unprotect
  Application.ScreenUpdating = False
  
  
'***FIRST PROCEDURE"
  Set rng = Range("q:q")
  
  If Not Intersect(Target, rng) Is Nothing Then
    If Target.Value = "**" Then Target.Value = Format(Date, "mm/dd/yyyy")
  End If

  If Not Intersect(Target, Range("A5:O5")) Is Nothing Then
      If Target.Value = "" Then
          ActiveSheet.Range("A7:O7").AutoFilter Field:=Target.Column
      Else
          ActiveSheet.Range("A7:O7").AutoFilter Field:=Target.Column, Operator:=xlFilterValues, Criteria1:=CStr(Target.Value)
      End If
  End If
  
  
'***SECOND PROCEDURE
    If Not Intersect(Target, Range("D7:J2500 ,L7:M2500")) Is Nothing Then
        Select Case Target.Column
            Case 4 To 10
                If Target <> "" Then
                    With Target.Offset(, 14)
                        .Value = Now()
                        .NumberFormat = "dd/mm/yy  hh:mm AM/PM"
                    End With
                Else
                    Target.Offset(, 14).ClearContents
                End If
            Case Is = 12, 13
                If Target <> "" Then
                    With Target.Offset(, 13)
                        .Value = Now()
                        .NumberFormat = "dd/mm/yy  hh:mm AM/PM"
                    End With
                Else
                     Target.Offset(, 13).ClearContents
                End If
        End Select
    End If
  
    
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFiltering:=True
  Application.EnableEvents = True
  Application.ScreenUpdating = True
    
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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