excel vba - Just-recorded macro fails to execute - AdvancedFilter method of Range class failed -


i working microsoft office 2010.

i want create button refreshes 'advancedfilter' upon click.
did record macro in order replay actions.
macro fails @ first execution.

sub test() ' ' test macro '  workbooks("requirement_spec.xls") _     .sheets("requirements").range("a4:bu279").advancedfilter _         action:=xlfiltercopy, _         criteriarange:=range("a1:f5"), _         copytorange:=range("a11:bu11"), _         unique:=false end sub 

starting macro via excel's macro menu or via button results in error:

run-time error '1004':
advancedfilter method of range class failed

i didn't change character of automatically recorded macro when producing error message.
(i did line-breaking changes so)

i ran similar today excel 2013. coming here, noticed old question no real solution.

what found out, error not appear when range in sheet filter being selected. therefore, following worked me:

sub test() ' ' test macro ' dim wb workbook, wbsave workbook, _     ws worksheet, wssave worksheet, rsel range 'don't annoy users changing selection application.screenupdating = false 'save old selection values sure set wbsave = activeworkbook set wssave = activesheet set rsel = selection 'activate target workbook + select 'in case it's sheet in same test workbook set wb = workbooks("requirement_spec.xls") wb.activate sheets("filter").select range("a11").select 'apply filter     sheets("requirements").range("a4:bu279").advancedfilter action:=xlfiltercopy, _     criteriarange:=range("a1:f5"), copytorange:=range("a11"), unique:=false 'restore old selection sure wbsave.activate wssave.activate rsel.select 'allow screen updating again application.screenupdating = true end sub 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -