Help fixing this simple cut and paste macro

exceldata

New Member
Joined
Mar 2, 2016
Messages
44
Could you please help me fix this? I'm trying to use this code to cut and paste chunks of info (67 rows long) from column A of my sheet and setting it to start in F6. It's off a bit somehow, as it is not reliably cutting the info at the 67th row. I need it to cut 67 rows, then the next 67 rows, setting these just to the right of the first section that was cut (G6), and repeating this pattern.

It may be a problem caused by my data starting on Row 6 rather than Row 1. Can you please help? Thank you!

This is the code:

Option Explicit
Sub PasteMeans()
Dim lngEndRow As Long
Dim lngMyRow As Long
Dim intStep As Integer
Dim lngColOutput As Long

Application.ScreenUpdating = False

lngEndRow = Cells(Rows.Count, "A").End(xlUp).Row 'Find the last used row in column C.
intStep = 68 'Block of data to be copied
lngColOutput = 6 'Initial output column i.e. column D

For lngMyRow = 69 To lngEndRow Step intStep
Range("A" & lngMyRow & ":A" & lngMyRow + intStep - 1).Cut Destination:=Cells(6, lngColOutput)
lngColOutput = lngColOutput + 1
Next lngMyRow

Application.ScreenUpdating = True

MsgBox "Done", vbInformation
End Sub


Sub PasteMeans2()

Dim lngEndRow As Long
Dim lngMyRow As Long
Dim intStep As Integer
Dim lngColOutput As Long

Application.ScreenUpdating = False

lngEndRow = Cells(Rows.Count, "B").End(xlUp).Row 'Find the last used row in column C.
intStep = 68 'Block of data to be copied
lngColOutput = 6 'Initial output column i.e. column D

For lngMyRow = 69 To lngEndRow Step intStep
Range("B" & lngMyRow & ":B" & lngMyRow + intStep - 1).Cut Destination:=Cells(84, lngColOutput)
lngColOutput = lngColOutput + 1
Next lngMyRow

Application.ScreenUpdating = True

MsgBox "Done", vbInformation

End Sub
 

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 PasteMeans()
   Dim lngEndRow As Long
   Dim lngMyRow As Long
   Dim intStep As Integer
   Dim lngColOutput As Long
   
   Application.ScreenUpdating = False
   
   lngEndRow = Cells(Rows.Count, "A").End(xlUp).Row 'Find the last used row in column C.
   intStep = 67 'Block of data to be copied
   lngColOutput = 6 'Initial output column i.e. column D
   
   For lngMyRow = 67 To lngEndRow Step intStep
      Range("A" & lngMyRow).Resize(67).Cut Destination:=Cells(6, lngColOutput)
      lngColOutput = lngColOutput + 1
   Next lngMyRow
   
   Application.ScreenUpdating = True
   
   MsgBox "Done", vbInformation
End Sub
 
Upvote 0
Thanks so much! That didn't work when the data started in Row 6, but when I moved it up to start in A1, it worked great. Does that make sense? Thanks so much!
 
Upvote 0
Might have misunderstood what you wanted, try
Code:
Sub PasteMeans()
   Dim lngEndRow As Long
   Dim lngMyRow As Long
   Dim intStep As Integer
   Dim lngColOutput As Long
   
   Application.ScreenUpdating = False
   
   lngEndRow = Cells(Rows.Count, "A").End(xlUp).Row 'Find the last used row in column C.
   intStep = 67 'Block of data to be copied
   lngColOutput = 6 'Initial output column i.e. column D
   
   For lngMyRow = [COLOR=#ff0000]73 [/COLOR]To lngEndRow Step intStep
      Range("A" & lngMyRow).Resize(67).Cut Destination:=Cells(6, lngColOutput)
      lngColOutput = lngColOutput + 1
   Next lngMyRow
   
   Application.ScreenUpdating = True
   
   MsgBox "Done", vbInformation
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,710
Members
452,994
Latest member
Janick

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