Excel VBA error: Method 'Intersect' of object '_Global' failed -


i need adapt pivottable according content of specific cell. whole process works, when refresh, add, or modify content, following error message:

debug: run_time error '1004': method 'intersect' of object '_global' failed 

it can annoying whatever doing on file produces error message.

here code use (found on internet, not own):

option explicit const regionrangename string = "suppname" const pivottablename string = "pivottable1" const pivotfieldname string = "supplier_name" public sub updatepivotfieldfromrange(rangename string, fieldname string, _                                       pivottablename string)     dim rng range     set rng = application.range(rangename)      dim pt pivottable     dim sheet worksheet     each sheet in application.activeworkbook.worksheets         on error resume next         set pt = sheet.pivottables(pivottablename)     next     if pt nothing goto ex      on error goto ex      pt.manualupdate = true     application.enableevents = false     application.screenupdating = false      dim field pivotfield     set field = pt.pivotfields(fieldname)     field.clearallfilters     field.enableitemselection = false     selectpivotitem field, rng.text     pt.refreshtable      ex:     pt.manualupdate = false     application.enableevents = true     application.screenupdating = true  end sub public sub selectpivotitem(field pivotfield, itemname string) dim item pivotitem each item in field.pivotitems item.visible = (item.caption = itemname) next end sub private sub workbook_sheetchange(byval sh object, byval target range) if not intersect(target, application.range(regionrangename)) _ nothing updatepivotfieldfromrange _ regionrangename, pivotfieldname, pivottablename end if end sub 

the highlighted part of code is:

if not intersect(target, application.range(regionrangename)) _ nothing 

i've tried replace contents (like activeworksheet or sheet1 instead of application) here , there, no success far.

might problem occurs because target , regionrangename-region not on same sheet?

sub mytest() '---throws "run-time error '1004': method 'intersect' of object '_global' failed" msgbox iif(intersect(sheets(1).range("g1"), _     sheets(2).range("g:ac")) nothing, _         "no intersect", "intersects") end sub 

i found example here. if above not case, can use locals window find parents (i.e. worksheets) of ranges "target" , "application.range(regionrangename)" , see whether same @ time error thrown?


Comments