Repeat Cut and Paste

Hector89

New Member
Joined
Jul 30, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hello,

Im trying to learn VBA and Macros to write a code that will cut and paste specific parts of a row repetitively throughout the whole sheet and skipping a row. I have created this so far:

Range("C7 : H7") .Select
Selection. Cut
Range ("I6") .Select
ActivateSheet .Paste
Range("C9 : H9") .Select
Selection. Cut
Range ("I8") .Select
ActivateSheet .Paste
End Sub

What I need the code to do is to cut from C7 to H7 and then paste on I6. Then I need it to skip a row and do the same function, cut from C9 to H9 and paste on I8. I need this to happen on the whole sheet. I have read of something called loop but I dont know how to use it or if that would work.

Anyone's assistance is much appreciated.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Welcome to MrExcel (y)
Test this on a COPY of your worksheet

VBA Code:
Sub CopyPaste()
    Dim r As Long
    For r = 7 To Range("C" & Rows.Count).End(xlUp).Row Step 2
        Range("C" & r).Resize(, 6).Cut Range("I" & r - 1)
    Next
End Sub
 
Upvote 0
You are a genius mate!!!

if I can bug you with something else. It seems the code keeps going and going and I need to hit esc for it to stop and then it freezes the excel for a while.

I’ve tried to add after “Next” the following:

Next Until ActiveCell.Value = “ “

but it doesn’t work. Do you know how I could make it stop once there is nothing else to cut?
 
Upvote 0
I am very puzzled by your comment :unsure:
Did you amend the macro in any way ?
If you did, post the macro that you used

Otherwise tell me what the message box returns when you run this one liner against the sheet
VBA Code:
MsgBox Range("C" & Rows.Count).End(xlUp).Row
Does it return the row number of the last cell containing a value in column C ?
 
Upvote 0
My bad Yongle. Ignore my previous comment. It’s working like a charm.
 
Upvote 0

Forum statistics

Threads
1,216,525
Messages
6,131,183
Members
449,630
Latest member
parkjun

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