Combine two worksheet event code as one

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi,

I,m trying to combine the following two code as one code. Any help on this would be kindly appreciated.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
  Dim r As Long
  Dim m As Long
  Dim n As Long
  Dim wsh As Worksheet
  Dim lngSerial As Long
  If Not Intersect(Range("O6"), Target) Is Nothing Then
    Application.EnableEvents = False
    Range("F18:F37").ClearContents
    Range("N18:N37").ClearContents
    lngSerial = Range("O6")
    n = 17
    Set wsh = Worksheets("OrderData")
    m = wsh.Range("F" & wsh.Rows.Count).End(xlUp).Row
    For r = 5 To m
      If wsh.Range("B" & r) = lngSerial Then
        n = n + 1
        Range("F" & n) = wsh.Range("C" & r)
        Range("N" & n) = wsh.Range("G" & r)
      End If
    Next r
    Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim wshI As Worksheet
  Dim rng As Range
  If Not Intersect(Range("O6"), Target) Is Nothing Then
    Set wshI = Worksheets("Invoice")
    Set rng = wshI.Range("B:B").Find(What:=Range("O6").Value, LookAt:=xlWhole)
    If rng Is Nothing Or Range("O6") = "" Then
      Range("I9:I10,M9:M10,M15,O9:O11").ClearContents
    Else
      Range("I9") = rng.Offset(0, 13)
      Range("I10") = rng.Offset(0, 1)
      Range("M9") = rng.Offset(0, 11)
      Range("M10") = rng.Offset(0, 2)
      Range("M15") = rng.Offset(0, 5)
      Range("O9") = rng.Offset(0, 12)
      Range("O10") = rng.Offset(0, 10)
    
    End If
  End If
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,224,517
Messages
6,179,233
Members
452,898
Latest member
Capolavoro009

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