+ Reply to Thread
Results 1 to 11 of 11

Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

  1. #1
    Registered User
    Join Date
    03-18-2015
    Location
    São Paulo, Brazil
    MS-Off Ver
    2013
    Posts
    4

    Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    Hi guys,

    Can anyone help me?

    I'm trying to make this code copy a range to clipboard and than paste it as .PasteEspecial but i'm geting an error.

    Error: 1004
    Application-defined or Object-defined error

    Heres the code:

    Please Login or Register  to view this content.
    Thank you guys.

  2. #2
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    If I am not mistaken you need to SET the ranges CabCol and CabLin, which is likely causing that error or this issue

    Please Login or Register  to view this content.
    -If you think you are done, Start over - ELeGault

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    Can you attach a workbook? is the spelling of the workbook and sheetname right? also have you checked the values of CabLin and CabCol when the error happens?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    If I am not mistaken you need to SET the ranges CabCol and CabLin, which is likely causing that error or this issue

    Please Login or Register  to view this content.
    Really any Defined Range... and it is good habit to also set to Nothing at the end of your run

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    Quote Originally Posted by ELeGault View Post
    If I am not mistaken you need to SET the ranges CabCol and CabLin, which is likely causing that error or this issue

    Please Login or Register  to view this content.
    CabLin and CabCol are numeric values I believe... that get their value from those ranges. I think they are just a variable for row and column, not actual Ranges.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    You need to fully qualify all your range and cells references with workbook and sheet.

  7. #7
    Registered User
    Join Date
    03-18-2015
    Location
    São Paulo, Brazil
    MS-Off Ver
    2013
    Posts
    4

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    Quote Originally Posted by Arkadi View Post
    CabLin and CabCol are numeric values I believe... that get their value from those ranges. I think they are just a variable for row and column, not actual Ranges.
    Yes, they are numeric values, going from 1 to 20 maximun, CabCol is the numeric value of the column i want to set and CabLin is the numeric value of the row.

  8. #8
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    @ELeGault: that's not the case. Obviously CabCol and CabLin are column and row number, not range object. Evident also from the way it is used later in the code.

    @rcarneiro: do you have "Divisor 2.0.xlsm" already open? also are you certain you have numbers in B2 and B4?
    If you are pleased with a member's answer then use the Star icon to rate it.

  9. #9
    Registered User
    Join Date
    03-18-2015
    Location
    São Paulo, Brazil
    MS-Off Ver
    2013
    Posts
    4

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    Quote Originally Posted by buran View Post
    @ELeGault: that's not the case. Obviously CabCol and CabLin are column and row number, not range object. Evident also from the way it is used later in the code.

    @rcarneiro: do you have "Divisor 2.0.xlsm" already open? also are you certain you have numbers in B2 and B4?
    Yes, the whole code just copies from worksheet (2) the matching criteria filtered and then copy to another created worksheet (ws.destino).

    I'll make sure is Divisor 2.0 which is open in the moment.

    Edit. Yes, Divisor 2.0 is open and active when i'm trying to Copy the Range, but it gives me the error anyways.
    Last edited by rcarneiro; 03-18-2015 at 04:09 PM.

  10. #10
    Registered User
    Join Date
    03-18-2015
    Location
    São Paulo, Brazil
    MS-Off Ver
    2013
    Posts
    4

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    The thing is:

    I was using it like this:
    Please Login or Register  to view this content.
    And it was all fine.

    But then I need to make the columns dynamic, thats why I used Cells inside .Range and now I get the error.

    Anyone know anything about the .Range(Cells(x,x),Cells(x,x)) and why it is giving me an error?

    Thanks

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Trying to use .Range(Cells(x,x),Cells(x,x)).Copy with no success

    Cells refers to the active worksheet unless qualified.

    Please Login or Register  to view this content.
    You need the dot in front of Range if you use a literal range string:

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Trying to lock cells on protected sheet, no success.
    By tv69 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2013, 01:45 PM
  2. Copy range of cells to other cells based on first cells value
    By bluestarCVO in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2013, 10:02 AM
  3. [SOLVED] VBA Copy a range of cells values using the range of cells in a formula (which will change)
    By murtaep in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 06-05-2012, 07:59 AM
  4. Replies: 2
    Last Post: 05-31-2012, 05:37 AM
  5. Replies: 2
    Last Post: 09-24-2005, 08:05 PM

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