Copy and paste non-adjacent cells

robertdseals

Active Member
Joined
May 14, 2008
Messages
334
Office Version
  1. 2010
Platform
  1. Windows
Hello,
I want to copy cells A3-A8 and A10-A14 and A16-A19. Then I want to paste them in cells F3-F8 and F10-F14 and F16-F19. I don't want to copy A3-A8 and paste it into F3-F8, then copy A10-A14 and past it into F10-F14...I want to copy all at once and paste all at once. And, my paste will be on a different tab (or maybe even a different worksheet) so I don't care if the copy is one macro and the paste is a second.

Right now, I can copy A3-A8 and A10-A14 and A16-A19. But when I go to paste it, it pastes into F3-F17.


Thoughts?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
Option Explicit


Sub cpyPst()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    s1.Range("A3:A8").Copy s2.Range("F3")
    s1.Range("A10:A14").Copy s2.Range("F10")
    s1.Range("A16:A19").Copy s2.Range("F16")
End Sub
 
Upvote 0
Almost, but this still copies then pastes then copies then pastes....I need to do all the copy first, then all the paste.
 
Upvote 0
Apologies. I don't have an alternate solution for you. When I attempted to use the Union function it did not get expected results.

Question: What difference does it make if this does not paste all at once? It might help in solving if there was a rationale explanation.
 
Upvote 0
Right now, I have to copy from one specific column in one spreadsheet, and copy it over to another specific column in another spreadsheet. I want to use a "relative reference" so it will copy down from whichever column my cursor is in. In addition, the rows between the numbers I have contain formulas so I don't want to copy the entire row and paste it. If I can copy all the numbers I need from one sheet (non-adjacent cells) and paste them into the corresponding locations on the new sheet, I wouldn't have to keep going back and forth to copy and paste. I hope that makes some sense. Thanks for your assistance.
 
Upvote 0
The only way I see this would be to copy the entire range and paste it to the new location. Then run a loop on the new range using this type of code to determine if there is a formula and then clearing the contents of that cell if true.

Code:
if range("F" & i).HasFormula = True then
range("F"& i).clearcontents
 
Upvote 0
That worked (with some minor changes).
Sub Macro5()
MyValue = InputBox("what column", "what col")
For dd = 1 To 1000
If Range(MyValue & dd).Offset(0, -1).HasFormula = True Then
Range(MyValue & dd).Offset(0, -1).Copy Range(MyValue & dd)
End If
Next dd


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

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