Cut and paste cells 24 cols over on same row

HowdeeDoodee

Well-known Member
Joined
Nov 15, 2004
Messages
599
If cells in col A on any row contain the letters C&P, I need a macro to cut and paste all filled cells in any row beginning at col A. I need to paste the cut cells beginning at col X on the same row the cells were in to start with. Some cells in the sheet are merged cells which I cannot do anything about at the moment. I did not create the sheet, I am just trying to work with it.

Said anothe way...

I want to cut and paste 24 cols over to the right, any group of filled cells on any row if col A in any row contains the letters C&P.

Thank you for your time and for any replies.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi HowdeeDoodee,

How about something like this;

Code:
For i = 1 To Range("A" & Rows.count).End(xlUp).Row
    If Cells(i, 1) = "C&P" Then
        Range("A" & i & ":Y" & i).Copy Range("X" & i)
    End If
Next i
 
Upvote 0
If cells in col A on any row contain the letters C&P, I need a macro to cut and paste all filled cells in any row beginning at col A. I need to paste the cut cells beginning at col X on the same row the cells were in to start with. Some cells in the sheet are merged cells which I cannot do anything about at the moment. I did not create the sheet, I am just trying to work with it.

Said anothe way...

I want to cut and paste 24 cols over to the right, any group of filled cells on any row if col A in any row contains the letters C&P.

Thank you for your time and for any replies.
This does not Cut and Paste and may not achieve the result you want. However, if it does, it has the advantage of avoiding the looping which can be a little slow if you have a lot of rows.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> MoveOver()<br>    <SPAN style="color:#00007F">Dim</SPAN> MoveRange <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(, 21))<br>        .AutoFilter field:=1, Criteria1:="=C&P"<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> MoveRange = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br>        .AutoFilter<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> MoveRange <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        MoveRange.Insert Shift:=xlToRight<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Thank you to both of you. Peter, I tried your code first and it works fine. Thank you again. Your help is really appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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