VBA Copy data ignore formatting

exo33

New Member
Joined
Oct 29, 2014
Messages
33
Happy Monday everyone!

Is there a quick way to modify my code below to avoid Excel copying formatting from one sheet to another. Basically, I want to copy values only from "Sheet1" to "Template". I know how to do it using Select, Copy & Paste commands but I find my code much simpler and efficient. Thanks in advance!

Code:
Sub cpydata()Sheets("Sheet1").Select
Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Copy Worksheets("Template").Range("D8")
Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row).Copy Worksheets("Template").Range("H8")
'other columns to follow...


End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You can do it like
Code:
Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Copy
Worksheets("Template").Range("D8").PasteSpecial xlPasteValues
 
Upvote 0
Try:
Code:
Sub cpydata()
    With Sheets("Sheet1")
        .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row).Copy
        Worksheets("Template").Range("D8").PasteSpecial xlPasteValues
        .Range("B1:B" & .Cells(Rows.Count, "B").End(xlUp).Row).Copy
        Worksheets("Template").Range("H8").PasteSpecial xlPasteValues
    End With
    'other columns to follow...
End Sub
What other columns do you want to copy and where do you want to paste?
 
Upvote 0
Another option maybe...

Code:
Sub cpydata()
    With Sheets("Sheet1")
        With .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row)
            Worksheets("Template").Range("D8").Resize(.Rows.Count, .Columns.Count).Value = .Value
        End With
        With .Range("B1:B" & .Cells(Rows.Count, "B").End(xlUp).Row)
            Worksheets("Template").Range("H8").Resize(.Rows.Count, .Columns.Count).Value = .Value
        End With
        'other columns to follow...
    End With
End Sub
 
Upvote 0
All of these tips will work! Thanks everyone!

Try:
Code:
Sub cpydata()
    With Sheets("Sheet1")
        .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row).Copy
        Worksheets("Template").Range("D8").PasteSpecial xlPasteValues
        .Range("B1:B" & .Cells(Rows.Count, "B").End(xlUp).Row).Copy
        Worksheets("Template").Range("H8").PasteSpecial xlPasteValues
    End With
    'other columns to follow...
End Sub
What other columns do you want to copy and where do you want to paste?

I have a bunch of them. I didn't want to make my post too messy... I can use your tip and copy for the rest of my code. Thanks again!
 
Upvote 0
Glad to help. :) Glad to help. :) I forgot to add this line of code:
Code:
Application.CutCopyMode = False
just above
Code:
End With
 
Last edited:
Upvote 0
I just tested this code on the entire range and a strange thing happened. Two columns did not copy properly i.e. only 6 top values were copied to Template tab from columns L and N. :confused: There are a few blank cells but that doesn't seem to be the issue.... Any ideas? It makes no sense to me whatsoever.

Code:
    With Sheets("Sheet1")
    
        .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row).Copy
        Worksheets("Template").Range("D8").PasteSpecial xlPasteValues
        .Range("B1:B" & .Cells(Rows.Count, "B").End(xlUp).Row).Copy
        Worksheets("Template").Range("H8").PasteSpecial xlPasteValues
        .Range("C1:C" & Cells(Rows.Count, "C").End(xlUp).Row).Copy
        Worksheets("Template").Range("E8").PasteSpecial xlPasteValues
        .Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row).Copy
        Worksheets("Template").Range("F8").PasteSpecial xlPasteValues
        .Range("E1:E" & Cells(Rows.Count, "E").End(xlUp).Row).Copy
        Worksheets("Template").Range("G8").PasteSpecial xlPasteValues
        .Range("Q1:Q" & Cells(Rows.Count, "Q").End(xlUp).Row).Copy
        Worksheets("Template").Range("I8").PasteSpecial xlPasteValues
[B]        .Range("L1:L" & Cells(Rows.Count, "L").End(xlUp).Row).Copy[/B]
[B]        Worksheets("Template").Range("K8").PasteSpecial xlPasteValues[/B]
        .Range("M1:M" & Cells(Rows.Count, "M").End(xlUp).Row).Copy
        Worksheets("Template").Range("J8").PasteSpecial xlPasteValues
[B]        .Range("N1:N" & Cells(Rows.Count, "N").End(xlUp).Row).Copy[/B]
[B]        Worksheets("Template").Range("L8").PasteSpecial xlPasteValues[/B]
        .Range("O1:O" & Cells(Rows.Count, "O").End(xlUp).Row).Copy
        Worksheets("Template").Range("N8").PasteSpecial xlPasteValues
        .Range("F1:F" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
        Worksheets("Template").Range("R8").PasteSpecial xlPasteValues
        .Range("H1:H" & Cells(Rows.Count, "H").End(xlUp).Row).Copy
        Worksheets("Template").Range("S8").PasteSpecial xlPasteValues
            
   Application.CutCopyMode = False
    End With


End Sub



When i change above code (for column L or N) to a more simplistic form it works properly :eeek::

Code:
Sub Macro2()    Sheets("Sheet1").Select
    Range("L1:L" & Cells(Rows.Count, "L").End(xlUp).Row).Select
    Selection.Copy
    Sheets("Template").Select
    Range("K8").Select
    ActiveSheet.Paste
End Sub



Update:

Just tested again (same code) and column N copied properly. Column L is still experiencing the same issue.....:confused: Is it just Excel going crazy?
 
Last edited:
Upvote 0
You are lucky that all the other columns are copying correctly.
If you look at the first two copy lines you have
Code:
.Range("A1:A" & [COLOR=#ff0000].[/COLOR]Cells(Rows.Count, "A").End(xlUp).Row).Copy
note the . infront of Cells.
That is missing from the other lines.
 
Upvote 0
You are lucky that all the other columns are copying correctly.
If you look at the first two copy lines you have
Code:
.Range("A1:A" & [COLOR=#ff0000].[/COLOR]Cells(Rows.Count, "A").End(xlUp).Row).Copy
note the . infront of Cells.
That is missing from the other lines.

Duh! Thanks! This fixed the issue.
 
Upvote 0
You're welcome & thanks for the feedback.
If you're interested you can also write the code like
Code:
Sub exo33()
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Array("A1", "D8", "B1", "H8", "C1", "E8", "D1", "F8", _
               "E1", "G8", "Q1", "I8", "L1", "K8", "M1", "J8", _
               "N1", "L8", "O1", "N8", "F1", "R8", "H1", "S8")
   
   With Sheets("sheet1")
      For i = 0 To UBound(Ary) Step 2
         .Range(Ary(i), .Cells(Rows.count, Left(Ary(i), 1)).End(xlUp)).Copy
         Worksheets("Template").Range(Ary(i + 1)).PasteSpecial xlPasteValues
      Next i
   Application.CutCopyMode = False
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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