Pasting a selection 5 columns to the left

Hmerman

Board Regular
Joined
Oct 2, 2016
Messages
102
Hello All,

I am using Find & Select to Find a specific text string (e.g. "Home") in a column with 16000 rows.
Once the selection is found I Select all and copy the selection using Ctrl+C.
*I do this without using vba.

What I want to do is to paste that selection as it is, within the same rows to a column 5 rows to the left. For instance pasting row 100:120,200:202 ect in Column F to row 100:120,200:202 ect in Column A.
Using vba.

My code does not yield the desired result.
Code:
Selection.Offset(0, -2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
Can someone please assist me in this endeavour?

Friendly Regards
Herman
 
No, it did not work correctly because is was not designed to handle non-contiguous ranges (look at the second and beyond sub-ranges... you will see they are not correct)...

You are correct.

I tried:
Code:
Sub CopyLeftFiveColumns()
  Dim Ar As Range
  For Each Ar In Selection.Areas
    If Ar.Column >= 5 Then Ar.Offset(, -5).Value = Ar.Value
  Next
End Sub

Your code cycles through all the non-contiguous selections and pastes it precisely where I want it.

Thanks a million.

Have a gr8 day in Usa.

Friendly Regards
Herman
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Just to show why previous attempts did not work.
Of course none of our proposals worked because we all missed that the OP was describing the selection of non-contiguous ranges in his original message. I am pretty sure what I posted in Message #7 will do what the OP actually asked for.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,800
Members
449,337
Latest member
BBV123

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