Shorter way to right this copy and Paste code

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
is there a shorter way to right this code? I am copying a column from a table. I am doing this for multiple columns, so it would be helpful if there was a shorter version. Note, I cannot copy and paste the entire table because not all column get pasted to the other location. And the order of the columns are different.

Thanks

Code:
Sub Macro1()
'
' Macro1 Macro
'

'
    Sheets("PP_Material_Assoc_Costs").Select
   
    Range("PP_Material_Assoc_Costs[TASK ID]").Select
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("A3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Material ID]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("B3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Ref ID]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("C3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
   
    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Resource]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("D3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Amount]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("L3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("X3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Link Qty]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("M3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
   
    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Link Spead]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("N3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
   
    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Curve]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("T3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
    Sheets("PP_Material_Assoc_Costs").Select
    Range("PP_Material_Assoc_Costs[Spread Method]").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Material Assoc Costs").Select
    Range("U3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
hi so allot of repitition in there, but your 1st 2 copy and paste may work like the below, untested and please test on a data copy.

if it works tidy up the others?

VBA Code:
    Range("PP_Material_Assoc_Costs[TASK ID]").Copy
    Range("'Material Assoc Costs'!A3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  
    Range("PP_Material_Assoc_Costs[Material ID]").Copy
    Range("'Material Assoc Costs'!B3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

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