Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

How to solve Run-time error '1004' ?

0

HI Sir,

I have a rectangle button in excel sheet assigned macro. 

Without protected sheet when I click that button; my macro run easily [data will autofilter]

But, with protected sheet it will show Run-time error '1004'.

In macro my command is like below.

Range("A14:j57").AutoFilter Field:=6, Criteria1:=">0"

Please solve this.

Answer
Discuss

Answers

0
Selected Answer

Naga

You need to unprotect the sheet before your macro runs (then re-protect after). Add these lines either side of your 

...
Worksheets("Sheet1").Unprotect
Range("A14:J57").AutoFilter Field:=6, Criteria1:=">0"
' Other lines of code
Worksheets("Sheet1").Protect
changing the bit in bold to suit.

If your sheet has a password, use:

Worksheets("Sheet1").Unprotect "Password"
changing the bits in bold to suit and likewise for .Protect..
Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login