Multiple Columns Copied - VBA

mattbarb

Board Regular
Joined
Mar 22, 2018
Messages
54
Office Version
  1. 365
Platform
  1. MacOS
Hi,

Im trying to copy over a number of columns to other columns using a VBA. I tried adapting a script i found but it's not working, any help would be really appreciated:

Code:
Sub PasteSpecial_ValuesOnly()
'PURPOSE: How To Paste Values Only With PasteSpecial
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
  
   
'Copy A Range of Data
  Worksheets("Plan").Range("J16:J37").Copy
  Worksheets("Plan").Range("P16:P37").Copy
  
'PasteSpecial Values Only
  Worksheets("Plan").Range("M16:M37").PasteSpecial Paste:=xlPasteValues
  Worksheets("Plan").Range("S16:S37").PasteSpecial Paste:=xlPasteValues
  
'Clear Clipboard (removes "marching ants" around your original data set)
  Application.CutCopyMode = False
  
End Sub

Many thanks!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How about
Code:
Sub mattbarb()
   With Worksheets("Plan")
      .Range("M16:M37").Value = .Range("J16:J37").Value
      .Range("S16:S37").Value = .Range("P16:P37").Value
   End With
End Sub
 
Upvote 0
Note that what you did wrong originally is that you need to complete the first copy before you start the second!
It cannot hold two different values in the clipboard at the same time, and remember what order that you want them in.

But Fluff's code is more efficient than using that method.
 
Last edited:
Upvote 0
Hi,

Many thanks for helping. When i use this it just seems to remove the values and doesn't copy and paste, am I doing something wrong?


How about
Code:
Sub mattbarb()
   With Worksheets("Plan")
      .Range("M16:M37").Value = .Range("J16:J37").Value
      .Range("S16:S37").Value = .Range("P16:P37").Value
   End With
End Sub
 
Upvote 0
That should copy the values from J16:J37 to M16:M37 and from P16:P37 to S16:S37
Is that what you wanted?
 
Upvote 0
|Hi, yes thats right, but doesn't seem to work. it just seems to remove values.

That should copy the values from J16:J37 to M16:M37 and from P16:P37 to S16:S37
Is that what you wanted?
 
Upvote 0
Which values are being removed?
 
Upvote 0
J16:J37 and M16:M37 are removed. And nothing is pasted. Thanks
 
Upvote 0
The code from post#2 does not remove the values from J16:J37
It will remove the values from M16:M37 if J16:J37 is empty
Have you made any changes to the code I posted?
 
Upvote 0
The code from post#2 does not remove the values from J16:J37
It will remove the values from M16:M37 if J16:J37 is empty
Have you made any changes to the code I posted?


Thanks, all working now!
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,073
Members
449,205
Latest member
Healthydogs

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