I'm trying to filter out unique values. I can't figure out what is wrong with my code. It is an application-defined or object-defined error. What am I defining wrong?
Please Login or Register to view this content.
I'm trying to filter out unique values. I can't figure out what is wrong with my code. It is an application-defined or object-defined error. What am I defining wrong?
Please Login or Register to view this content.
Works fine for me. Do you have the right sheet names? Correct Range (Should it be A2:A16)?
Thanks stnkynts. I figured out the problem, but I don't understand why. Let me give you another example. Here is my code:
I notice that when I am active in the Macro1 worksheet, it works fine. But when I move to the Macro2 worksheet and run the same code, I get a Run-time error 1004. I don't understand why I cannot work across several worksheets when I defined both worksheets.Please Login or Register to view this content.
The same thing happened with the AdvancedFilter application I posted earlier. There, I set a command button in Sheet 2. When I run the code while having Sheet 1 active, it runs fine. But when I click on the command button in Sheet 2 or when I am active in Sheet 2, I get the Run-time error 1004 again.
Also, I have the codes written inside a module of the workbook, not in any specific worksheet object.
It is because you have to reference the worksheet on each range including a cells range.I notice that when I am active in the Macro1 worksheet, it works fine. But when I move to the Macro2 worksheet and run the same code, I get a Run-time error 1004. I don't understand why I cannot work across several worksheets when I defined both worksheets.
Please Login or Register to view this content.
[QUOTE=bananajelly;3641823]Thanks stnkynts. I figured out the problem, but I don't understand why. Let me give you another example. Here is my code:
..and as an aid to reading code subsequently it's generally regarded as good practice to have some sort of reference to the variable type in the name.Please Login or Register to view this content.
e.g stMyVariable As String, rMyVariable As Range, wsMyVariable as Worksheet, lMyVariable as Long, etc..
Richard Buttrey
RIP - d. 06/10/2022
If any of the responses have helped then please consider rating them by clicking the small star icon below the post.
Thanks stynkynts. It worked. I had to do the same thing with Key1:=Columns(4).
Please Login or Register to view this content.
Richard, I never knew that! Thanks so much for telling me! I actually posted a separate question just to confirm this, and you're totally right. All this time...
I'm having the same problem again! I get a run-time error 1004. Am I declaring my variables incorrectly? I don't know why it works sometimes, but not other times.
Here is my code:
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks