+ Reply to Thread
Results 1 to 8 of 8

Code tweak needed: Copy macro not copying formats only values (with getobject)

  1. #1
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Code tweak needed: Copy macro not copying formats only values (with getobject)

    Hi Peeps,
    I managed to find some really neat copying code which i'd preferably like to keep but i've noticed this month that it doesn't copy formats only values. Is there a quick tweak i could insert into my below code to include this?
    TIA

    Please Login or Register  to view this content.
    Last edited by Gti182; 10-18-2012 at 05:07 AM.

  2. #2
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    I've not the time to check this but you could try adding
    ThisWorkbook.Sheets("Coal").[A1:Z500].NumberFormat = .Sheets(2).[A1:Z500].NumberFormat
    after the one with .value.

    Of course the sequence selection.copy... selection.paste copies values plus all formats including conditional ones.

  3. #3
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Unhappy Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    thanks for the reply, no luck with numberformat though

  4. #4
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    anybody else?

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

    Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    How about:

    Please Login or Register  to view this content.
    _________________
    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!)

  6. #6
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    455

    Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    thanks for the replies. managed to find this bit of code which i've used

    With GetObject(c00 + c02)
    .Sheets(1).[A1:Z500].Copy Destination:=ThisWorkbook.Sheets("TV").[A1:Z500]
    .Close True
    End With

  7. #7
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    Quote Originally Posted by Gti182 View Post
    thanks for the replies. managed to find this bit of code which i've used

    With GetObject(c00 + c02)
    .Sheets(1).[A1:Z500].Copy Destination:=ThisWorkbook.Sheets("TV").[A1:Z500]
    .Close True
    End With
    I shoukld have mentioned that; it did occur to me. I think it is a little known feature that I only came across a month or two ago and haven't had to use yet, but it is a very useful shortcut.

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

    Re: Code tweak needed: Copy macro not copying formats only values (with getobject)

    Yes, your technique transfers ALL characteristics of one range to another. I thought you were trying to maintain the "values only" transfer which would remove any reference formulas so the data was "flat", then apply the formatting as well.

    If that takes care of your need, please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ 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