Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts

    Copy a cell format from one cell to another?

    Hopefully, a quick one for the experts:

    How can I, using VBA, copy a cell's formatting from one cell to another? I don't know what format has been applied so I just want to copy everything.

    Thanks

    Alan

    My code looks like:

    Code:
    for i = 1 to 300
    newsheet.cells(i,1) = oldsheet.cells(i,1) <=== this line works and I've tested it
    newsheet.cells (format) (i,1) = oldsheet.cells (format) (i,1)  <=== This line is my unknown
    next i

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Alan,

    Here's the generic code.
    Code:
    Option Explicit
    
    Sub CopyFormats()
    
        Range("A1").Select
        Selection.Copy
        Range("C1").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
    End Sub
    BTW: The easiest way to do this kind of thing is to use the Record Macro function on the Developer tab then do the keystrokes necessary and review and modify the created code. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    alan sh (2013-08-22)

  4. #3
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts
    OK - I've done it differently (I was playing) as all I really needed was the bolding.

    newsheet.Cells(i, 1).Font.Bold = oldsheet.Cells(i,1).Font.Bold

    Now, how to get the fill colour?

    Alan

  5. #4
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,633
    Thanks
    115
    Thanked 647 Times in 590 Posts
    alan,

    You can use the following format. Change the 7 to any of the following colors.

    HTH,
    Maud

    colors.png

    Code:
    Public Sub test()
    Cells(1, 1).Interior.ColorIndex= 7
    End Sub
    Last edited by Maudibe; 2013-08-22 at 13:34.

  6. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    How about:
    newsheet.Cells(i, 1).interior.color= oldsheet.Cells(i,1).interior.color
    Steve

  7. The Following User Says Thank You to sdckapr For This Useful Post:

    alan sh (2013-08-27)

  8. #6
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts
    Yep - that's what I want.

    Thanks

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •