+ Reply to Thread
Results 1 to 9 of 9

Copy Destination Syntax

  1. #1
    Registered User
    Join Date
    10-17-2008
    Location
    US
    Posts
    35

    Copy Destination Syntax

    I am attempting to create a macro that opens a file named "shrinkage-billing.xls", searches for a variable "PTOSH" in column A, copies the adjacent cell and pastes the data in another worksheet named "Shrinkage Report 2009.xls"

    The code follows ...

    Please Login or Register  to view this content.
    I get the following error when I run this macro:

    Run-time error '1004';
    Method 'Range' of object'_Global' failed

    I am not certain if I have the Offset syntax incorrect, or maybe the destination reference. As Shrinkage report 2009.xls is in fact the workbook that houses the macro, Can I use 'ThisWorkbook' instead of the actual filename? Also ... the data in Column B in "Shrinkage-Billing.xls" is in hh:mm format which does not paste well in excel. Any chance I can just copy the text before the : ??

    Any help would be so appreciated, as somehow I have been dubbed the excel-meister of my workplace. It's a lie I tell you!

    ~M
    Last edited by VBA Noob; 10-18-2008 at 01:51 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    If you're looking for the string PTOSH, you need to enclose it in quotes. There are other arguments to the Find method that default to the last used values; you should set them explicitly. And you had a syntax error in the Copy line unless the cell contained the string address of the range of interest.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-17-2008
    Location
    US
    Posts
    35

    Smile Copy Destation Syntax

    My hero!!

    Thank you so much for replying so quickly! Got the problem solved and today isn't even over yet.

    Just one follow-up question ... the data in Column B in "Shrinkage-Billing.xls" is in hh:mm format which does not paste well in excel. Is there any way to just copy the part of the cell before the colon?

    ~M
    Last edited by delirium; 10-17-2008 at 07:51 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Doesn't paste well?

    There is no colon in the underlying data, it's just a number. You can format it as [h] if you just want to see whole hours.
    Last edited by shg; 10-18-2008 at 12:43 AM.

  5. #5
    Registered User
    Join Date
    10-17-2008
    Location
    US
    Posts
    35

    Copy Destination Syntax

    I have attached a copy of the report and one of the underlying files. Please note the format of the "text" in row 'F' on the Calculation Tab in 'Shrinkage Report 2009.xls'. It cannot be formatted once pasted into even if the cell's format is already Number or HH:MM. As a result, the sum in row 'I' will not work. I figured the best way to combat this is to copy only the numbers before the colon in 'Shrinkage-Billing.xls' although that will skew the results ... just a paste special might work too.

    Thanks so much!

    ~M
    Attached Files Attached Files
    Last edited by delirium; 10-18-2008 at 09:59 AM.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,428
    The problem is caused by the leading space in the cells in the source data file.
    Ideally you would correct the Shrinkage-Billing.xls file so the times were actually times and not just text.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    10-17-2008
    Location
    US
    Posts
    35
    Unfortunately, that is not possible. Shrinkage-billing.xls is autorun from my workforce management software, I have attached a copy of the formatted excel option. I changed the macro to work with this report and ... oddly ... the result is the same.

    I am now trying to figure out how to modify the macro to Trim 1 space off the left side and then format the cell [h]:mm? I think this will resolve all issues.

    ~M
    Attached Files Attached Files
    Last edited by delirium; 10-18-2008 at 12:18 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    There are several ways you could do this. Here's one.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-17-2008
    Location
    US
    Posts
    35
    That does it! I'mma make you some brownies!!

    ~M

+ 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. speed - variables vs copy paste
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2008, 03:34 PM
  2. Macro to Copy value in a given destination cell
    By urtzi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2008, 12:08 PM
  3. excel no copy, users must use origonal
    By user phil in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-23-2008, 10:02 AM
  4. Copy selected data to a user defined destination
    By kaesuma in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2007, 02:25 PM
  5. Worksheet copy problem
    By Willow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2006, 09:56 AM

Tags for this Thread

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