excel - Setting Dynamic Range resulting in "Object Variable or with Block variable not set" error -
i have workbook designed refresh named ranges based on pivot table data. when pivot table refreshes, named range reset based on new values appear in pivot table.
i getting error "object variable or block variable not set" when tries set range named variable, there i'm doing wrong here cannot see?
sub refreshpivots() dim pt1 pivottable dim namefirst range dim config worksheet 'define worksheet set config = thisworkbook.worksheets("config") 'define pivot table ranges set pt1 = config.pivottables("pivottable1") 'clear current filters pt1.pivotfields("number").clearallfilters 'refresh pivots thisworkbook.refreshall 'set pivot table filters pt1.pivotfields("number").pivotitems("1").visible = true pt1.pivotfields("number").pivotitems("2").visible = false pt1.pivotfields("number").pivotitems("3").visible = false pt1.pivotfields("number").pivotitems("4").visible = false pt1.pivotfields("number").pivotitems("5").visible = false pt1.pivotfields("number").pivotitems("6").visible = false pt1.pivotfields("number").pivotitems("(blank)").visible = false 'remove old range thisworkbook.names("first").delete 'define range new name (**this error occurs**) namefirst = config.range("g4:g" & config.range("g" & rows.count).end(xlup).row) **<--error** 'apply new named range range(namefirst).name = "first" end sub
try setting range object.
set namefirst = config.range("g4:g" & config.range("g" & rows.count).end(xlup).row) namefirst.name = "first"
Comments
Post a Comment