copy paste range, values or formats?

SURFER349

Board Regular
Joined
Feb 22, 2017
Messages
50
So I've got this string of code that finds a sheet by name (source), then copies its data onto a combined sheet (destination) after the last row.

I pulled this from google, and not quite sure yet how the syntax works w/ the copyrng and vlaues vs formats.

How do I adjust this to preserve the formats of the source sheets?

Code:
Dim CopyRng As Range
Dim Destws As Worksheet
Dim ws As Worksheet
Dim Last As Long

Set Destws = ActiveWorkbook.Sheets("Sheet1")

For Each ws In ActiveWorkbook.Worksheets
     If LCase(ws.Name) Like LCase("source") Then
          Last = Lastrow(Destws) 'uses LastRow() sub listed above

          Set CopyRng = ws.Range("B1").CurrentRegion 'uses the current block of data
          
          CopyRng.Copy    'This statement copies values and formats.            
          With CopyRng    'paste values only, one row down from last row
               Destws.Cells(Last + 1, "A").Resize(.Rows.Count, .Columns.Count).Value = .Value
               Application.CutCopyMode = False
          End With
     End If
Next
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Assuming all the other lines of code works the way you want it to.

Change this line of code:
Code:
Destws.Cells(Last + 1, "A").Resize(.Rows.Count, .Columns.Count).Value = .Value



To this:
Code:
Destws.Cells(Last + 1, "A").Resize(.Rows.Count, .Columns.Count).PasteSpecial
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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