+ Reply to Thread
Results 1 to 3 of 3

Error on range selection in macro

  1. #1
    Registered User
    Join Date
    05-12-2009
    Location
    Udevalla, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    85

    Error on range selection in macro

    Hey guys.

    I got a problem and I just cannot find a solution to it.
    What I want my code to do is:
    1. Autofilter a list
    2. Select all values in column "B" in the filtered list
    3. Copy it to another sheet.

    The code runs when I change a ComboBox and the combobox value is the criteria used in the autofilter.

    Here is my code so far:

    Please Login or Register  to view this content.

    The code crashes when I try to Copy filtered range.
    I get this error message:

    Run-time Error '1004':
    Method 'Range' of object '_Worksheet' failes

    I get this error no matter what I do there.
    Even when I try something like this it still fails:

    Please Login or Register  to view this content.

    Any ideas? The sheet or workbook isnt password protected or anything.


    UPDATE:

    If I make a new macro with the code:

    Please Login or Register  to view this content.
    and use the Call function to run that code it all works fine.
    Very weird.
    Last edited by Carlsbergen; 11-11-2010 at 06:12 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Error on range selection in macro

    What column is being autofiltered? Column A? Column C?

    If it's column C, maybe something like this, notice we don't do any selecting or "activecell" referencing, VBA doesn't need to evaluate cells the way humans do, it can simply act if you give complete reference to the object(s):
    Please Login or Register  to view this content.
    I'm sure that will need some tweaking. Perhaps the sheet being copied to (underlined) is another sheetname, edit that.

    If you can't figure it out, post a copy of your workbook so we can look at the same thing. Click GO ADVANCED and use the paperclip icon to post up a desensitized copy of your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-12-2009
    Location
    Udevalla, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Error on range selection in macro

    Quote Originally Posted by JBeaucaire View Post
    What column is being autofiltered? Column A? Column C?

    If it's column C, maybe something like this, notice we don't do any selecting or "activecell" referencing, VBA doesn't need to evaluate cells the way humans do, it can simply act if you give complete reference to the object(s):
    Please Login or Register  to view this content.
    I'm sure that will need some tweaking. Perhaps the sheet being copied to (underlined) is another sheetname, edit that.

    If you can't figure it out, post a copy of your workbook so we can look at the same thing. Click GO ADVANCED and use the paperclip icon to post up a desensitized copy of your workbook.

    That worked like a charm!
    Thanks so much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1