Copy and Paste range to bottom of different worksheet and retain formatting?

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,233
Office Version
  1. 365
Platform
  1. Windows
Hey All

I've got a perfectly fine and working Macro but I need to tweak it and can't work it out :-/

I need to be able to Copy and Paste a range of cells from one worksheet to the bottom of another in the same workbook, that's what this code does;

Code:
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column

    For y = 1 To LastCol
        If Cells(1, y).Value = "Products" Then
            Range(Cells(2, y), Cells(NewLastRow, y)).Copy Sheets("Final").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
            FoundPr = True
        End If
        If Cells(1, y).Value = "ID" Then
            Range(Cells(2, y), Cells(NewLastRow, y)).Copy Sheets("Final").Range("D" & Rows.Count).End(xlUp).Offset(1, 0)
            FoundID = True
        End If
    Next y

The thing is that some of the cells it copies have background colours and I need those copying as well.

Is there a simple way I can do with that code?

Something like ".PasteSpecial xlPasteFormats" ?

Brain freeze on this one :(
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is the cell fill done by conditional format?
 
Upvote 0
Try pasteSpecial

Code:
        If Cells(1, y).Value = "Products" Then
            Range(Cells(2, y), Cells(NewLastRow, y)).Copy
            Sheets("Final").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
            Sheets("Final").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormats
            Application.CutCopyMode = False
            FoundPr = True
        End If

maybe even xlpasteall
 
Upvote 0
Not as far as I can tell :)

These are workbooks that have been completed by other people, they don't seem to have anything special about them but I don't know what has happened to them before I got them. I've just been tasked with combining them all into one worksheet :)

Thanks for the reply!
 
Upvote 0
In that case the cell colour should be copied along with the cell contents.
 
Upvote 0
In that case the cell colour should be copied along with the cell contents.

I thought that was the case, I've been properly confused with it!

The method suggested by davesexcel above also didn't work, I'd tried something similar to that already but I tried it anyway - Nope :(

Well. This is even odder than I thought then.

I'll see if I can see anything in the workbooks that could be causing weirdness, they've been out in the wild so anything could have happened with them.

(The whole searching for the column name thing is because people have messed with the templates they where given, adding and deleting columns willy nilly and so things aren't where they should be in most of the 65 workbooks I've to go through :-/ )
 
Upvote 0
If you have a look at Chip Pearson's site here there are some functions that might help to identify if it is CF
 
Upvote 0
Thanks Fluff, I'll take a look and see what is going on - Oh, the joys :(
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top