Results 1 to 2 of 2

Thread: VBA code to copy/paste the formatting of the entire workbook.

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    VBA code to copy/paste the formatting of the entire workbook.

    Hello Reader,

    I am trying to write a VBA code, which copy/pastes the formatting (just the cell background) of the used range of one workbook to the another. It should just copy/paste the cell background and nothing else formats say, fonts, cell styles etc.

    I have tried my best, but not yet reached the solution. If you have done something like this in the past, your help is much appreciated !

    PS: Both the worksheets from where the cell background is copied and where it is been pasted has the same sheet names and the same sheet structure.

    Thanks,
    Sourav

  2. #2
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    11
    Perhaps something along these lines (untested):
    Code:
    Sub blah()
    Set SceWkBk = ThisWorkbook  'or whatever the source workbook is.
    Set DestWkBk = Workbooks("something.xls")  'or whatever the estination workbook is.
    
    For Each SceSheet In SceWkBk.Sheets
      Set DestSht = DestWkBk.Sheets(SceSht.Name)
      For Each cll In SceSht.UsedRange.Cells
        DestSht.Range(cll.Address).Interior.ColorIndex = cll.Interior.ColorIndex
      Next cll
    Next SceSht
    End Sub
    I'm using Excel 2003 here right now and it might be you want to copy more/different cell properties across. Record a macro of your making some cell format changes of the ilk that you want to copy across, look at the code, and you can usually delete 90% of the properties therein as they're the default values anyway. If you're not sure, post a copy of the recorded macro here and say what aspects of the cell formatting you want to transfer.

Similar Threads

  1. Replies: 9
    Last Post: 07-02-2013, 10:02 PM
  2. VBA -- Copy/Paste across sheets
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 09-21-2012, 02:07 PM
  3. VBA Code to Open Workbook and copy data
    By Howardc in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 06:58 PM
  4. VBA code to copy data from source workbook
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 07-30-2012, 09:28 AM
  5. Replies: 9
    Last Post: 09-09-2011, 02:30 AM

Posting Permissions

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