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

Filter

0

this code every time giving me an error Run-Time error 1004 

method 'Range' of object_ worksheet failed 

Repc.Range("B8:P").AdvancedFilter Action:= _
xlFilterCopy, CriteriaRange:=.Range("F1:K2"), _
CopyToRange:=.Range("E16:O16"), Unique:=False
Answer
Discuss

Answers

0
Selected Answer

Amin 

You tried to define a range:

Repc.Range("B8:P").AdvancedFilter... 

but that doesn't define a range. Try:

Repc.Range("B8:P50").AdvancedFilter
but change the P row number to suit (you didn't attach a file so I'm just guessing 42 data rows) 
Discuss

Discussion

I want P to the end of the table because if Range("B8:P50"). so maybe will not give me any report after row 50 
Amin25 (rep: 16) Feb 2, '24 at 3:04 pm
Amin. I'm out, on my mobile phone so no VBA but you've seen how to determine the last row for a column (if not, look in the Tutorials section) so define a variable LstRw say, determine the last row in B (or P, whichever will be full) and use:
Repc.Range("B8:P" & LstRw).AdvancedFilter
John_Ru (rep: 6142) Feb 2, '24 at 3:14 pm
I need you to give me full course about it please 
Amin25 (rep: 16) Feb 2, '24 at 3:21 pm
I don't have time to "give you a course" but look at Don's tutorial:
Get the Last Row using VBA in Excel and use it to get the last row for LstRw (say).

If you want a course, buy Don's excellent VBA course on this site.
John_Ru (rep: 6142) Feb 2, '24 at 3:29 pm
I have attached the file the file you helped me with the code to delete from listbox and "Data" sheet, but in this file, I deleted some column so even I add numbers above the tables to know the columns number 
Amin25 (rep: 16) Feb 2, '24 at 3:42 pm
I will attach it here again 
Amin25 (rep: 16) Feb 2, '24 at 3:43 pm
I attached the file and really, I appreciate you too much 
Amin25 (rep: 16) Feb 2, '24 at 4:02 pm
Amin. Did you see the tutorial and fix the problem? If so, thanks for selecting my Answer. 

If not, please say but don't expect an answer soon- I'm out with friends. 
John_Ru (rep: 6142) Feb 2, '24 at 4:20 pm
Yes already, I attached the file here and I only want in UF frmCodeItem,   CbSubCategory to mention the table instead the column and also frmCode same 
Amin25 (rep: 16) Feb 3, '24 at 12:03 am
Mr. John, are you free?
Amin25 (rep: 16) Feb 3, '24 at 12:32 pm
I wasn't free (and please note that I'm not avaible live or "on demand" as you seem to think!). 
John_Ru (rep: 6142) Feb 5, '24 at 6:37 am
Add to Discussion


Answer the Question

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