+ Reply to Thread
Results 1 to 11 of 11

Macro only runs on sheet i recorded it on.

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro only runs on sheet i recorded it on.

    I have a macro that i recorded on the first tab of my spreadsheet. I need it to function on all the tabs, and it looks likeits hanging up because it specficially only works on the first tabe. Here is the code form the macro. Can you guys pleasehelp me figure out how to make it function on all the tabs of the workbook.

    Thanks,
    brian


    Please Login or Register  to view this content.
    Last edited by BF15; 09-19-2011 at 06:44 PM.

  2. #2
    Registered User
    Join Date
    09-19-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro only runs on sheet i recorded it on.

    just to add to this, all the tabs are excat copies of each other, other than having a different date. Im trying to use this macro to jsut simply be able to do a paste and it sort, and format the page.

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro only runs on sheet i recorded it on.

    Hello and welcome to the forum - unfortunately before we go any further you need to read the forum rules and use code tags around any code that you post. If you edit your original post then I'm sure somebody will be happy to help you.

  4. #4
    Registered User
    Join Date
    09-19-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro only runs on sheet i recorded it on.

    Quote Originally Posted by Andrew-R View Post
    Hello and welcome to the forum - unfortunately before we go any further you need to read the forum rules and use code tags around any code that you post. If you edit your original post then I'm sure somebody will be happy to help you.
    Ok, i think i wraped it correctly.

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro only runs on sheet i recorded it on.

    Yup, looks like the job.

    Macros written with the macro recorder are rather inefficient, because they have in a lot of selecting data which doesn't need to happen. It's late here in the UK, so rather than rewrite this properly I've just hacked it to work, but work it should...

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-19-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro only runs on sheet i recorded it on.

    Quote Originally Posted by Andrew-R View Post
    Yup, looks like the job.

    Macros written with the macro recorder are rather inefficient, because they have in a lot of selecting data which doesn't need to happen. It's late here in the UK, so rather than rewrite this properly I've just hacked it to work, but work it should...

    Please Login or Register  to view this content.
    I replaced my existing code on in th emacro with this.

    Now when i try to sue ctrl i to do the special paste it does not paste anything.

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro only runs on sheet i recorded it on.

    Please don't quote entire posts when replying, it just clutters up the thread.

    Is the Ctrl-i short-cut still assigned to the macro? That would be the first thing to check.

  8. #8
    Registered User
    Join Date
    09-19-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro only runs on sheet i recorded it on.

    Quote Originally Posted by Andrew-R View Post
    Please don't quote entire posts when replying, it just clutters up the thread.

    Is the Ctrl-i short-cut still assigned to the macro? That would be the first thing to check.
    Sorry about that.

    Ok, that was the problem. Now im having an issue when i run the macro.

    run-time error '1004':

    PasteSpecial method of Range class failed.

    Do you have any idea what could cause this?
    Thanks for all your help.

  9. #9
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro only runs on sheet i recorded it on.

    It looks like the issue is that you're trying to paste special without actually copying anything first - are you running this macro after selecting a range to copy?

  10. #10
    Registered User
    Join Date
    09-19-2011
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro only runs on sheet i recorded it on.

    Quote Originally Posted by Andrew-R View Post
    It looks like the issue is that you're trying to paste special without actually copying anything first - are you running this macro after selecting a range to copy?
    yes, im copying the datafrom a seperate spreadsheet. and trying to paste it into the one the macro is ran on.

  11. #11
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro only runs on sheet i recorded it on.

    OK, that's what's causing the problem. On the first pass through the worksheet loop you're pasting the data then turning the cut and paste mode off, so subsequent passes through have nothing to paste.

    Is it the range "Table2" that you're pasting?

+ 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