+ Reply to Thread
Results 1 to 11 of 11

Function call returns actual code instead of copied range

  1. #1
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Function call returns actual code instead of copied range

    I am baffled with this. I've never seen vba code pasted in the actual excel spreadsheet before. Here's the code I'm calling:
    Please Login or Register  to view this content.
    Here's how I'm calling it:
    Please Login or Register  to view this content.
    Here's what is returned and pasted in the spreadsheet:
    Sheets("Analog").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

    Any suggestions on how to copy and paste the range instead of the actual code would be great.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Function call returns actual code instead of copied range

    Hello rlg50,

    Welcome to the Forum!

    Here is the corrected and working code. Copy and Paste this code into a standard Module, and delete the old code.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 03-22-2012 at 01:19 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function call returns actual code instead of copied range

    Is the only thing that you changed was the arguments for GetInputAndCopyData?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Function call returns actual code instead of copied range

    Hello rlg50,

    I made a few other changes to the Sub as well. Also, I changed the line below which is in GetInputAndCopyData...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function call returns actual code instead of copied range

    OK. I see that now. I ran the code and I'm getting the following error: Paste method of worksheet class failed using the following code to call the above corrected code.

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Function call returns actual code instead of copied range

    Hello rlg50,

    That is because ""EMS Composite Name"" is not a valid Range name. To me it looks like a column header.

  7. #7
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function call returns actual code instead of copied range

    Please Login or Register  to view this content.
    I may need to clarify something. What I'm doing is, adding worksheets from another workbook into my workbook, say I import a worksheet named Sheet2. From "Sheet 2", I want to copy all data in column "EMS Composite Name" and paste it in "Analog". If I run the following, again, it pastes the actual code in my worksheet.

    Please Login or Register  to view this content.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Function call returns actual code instead of copied range

    Hello rlg50 ,

    Is "EMS Composite Name" a named range, column header, what?

  9. #9
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function call returns actual code instead of copied range

    It is a column header. So I pass the worksheet name and header name, then search for that column and then copy the data under it, return the copied data and paste it into another worksheet.

  10. #10
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function call returns actual code instead of copied range

    It might help if I told you that the header is located on row 6 and there are about 15 other names on that row, so I need to select the correct column with "EMS Composite Name" in it.

  11. #11
    Registered User
    Join Date
    03-22-2012
    Location
    united states
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function call returns actual code instead of copied range

    The jpg attached shows a quick illustration of what I'd like to do. Also, if it's easier to just go ahead and paste the copied data instead of returning it and pasting it, that will be fine too.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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