sometimes show "Method 'Range' of object '_Worksheet' failed" error and maybe not error!!

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello
I'm not sure why suddenly shows "Method 'Range' of object '_Worksheet' failed" error ,sometimes in this line
VBA Code:
If Not Intersect(Target, Range("E21:E" & Cells(Rows.Count, "E").End(xlUp).Row)) Is Nothing Then
and sometimes in this
VBA Code:
    x = Evaluate("=Match(""" & Target.Offset(, -3) & """ & """ & Target.Offset(, -2) & """ & """ & Target.Offset(, -1) & """,'PriceList'!B1:B" & lr & "&'PriceList'!C1:C" & lr & "&'PriceList'!D1:D" & lr & ",0)")
and somtimes there is no error !
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)



Dim x, lr As Long: With Sheets("PriceList"): lr = .Cells(.Rows.Count, 1).End(xlUp).Row: End With
If Not Intersect(Target, Range("E21:E" & Cells(Rows.Count, "E").End(xlUp).Row)) Is Nothing Then
    If Target.Cells.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    x = Evaluate("=Match(""" & Target.Offset(, -3) & """ & """ & Target.Offset(, -2) & """ & """ & Target.Offset(, -1) & """,'PriceList'!B1:B" & lr & "&'PriceList'!C1:C" & lr & "&'PriceList'!D1:D" & lr & ",0)")
    If Not IsError(x) Then
        With Sheets("PriceList")
        If Sheets("INVOICE").Range("G1") = "ss" Then
            .Range("E" & x) = .Range("E" & x) - Target.Value
            MsgBox ":this item is not existed " & vbLf & .Range("B" & x).Value & "  " & .Range("C" & x).Value & "  " & .Range("D" & x).Value & "  " & .Range("E" & x).Value, vbInformation
            ElseIf Sheets("INVOICE").Range("G1") = "pp" Then
            .Range("E" & x) = .Range("E" & x) + Target.Value
            MsgBox .Range("E" & x).Value
            ElseIf Sheets("INVOICE").Range("G1") = "rr" Then
            .Range("E" & x) = .Range("E" & x) + Target.Value
            MsgBox .Range("E" & x).Value
             ElseIf Sheets("INVOICE").Range("G1") = "tt" Then
            .Range("E" & x) = .Range("E" & x) - Target.Value
            MsgBox .Range("E" & x).Value
            End If
            
        End With
    Else
        MsgBox "ITEM DOES NOT EXIST", vbInformation, ""
    End If
    Application.EnableEvents = True
End If
If Target.Column = 2 And Target.Row > 20 Then
Target.Offset(, -1).Value = Target.Row - 20
End If



End Sub

I'm so confused how should fix this error!!:mad::mad::mad:
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

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