ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Copying Select Repeating Cells in a Column (https://www.excelbanter.com/excel-worksheet-functions/239372-copying-select-repeating-cells-column.html)

Shalebot

Copying Select Repeating Cells in a Column
 
How would I go about creating a macro to select and copy certain cells in a
column and get them to paste in a blank column back-to-back (ie: selecting
every fourth cell in a column and pasting it one after another in a new
column)?

I tried finding something like this in these and other discussion groups,
but I'm not sure what to even call it, so my ability to find what I'm trying
to describe on my own is virtually nonexistent.

Any help would be greatly appreciated.

Libby

Copying Select Repeating Cells in a Column
 
If you have a row of data say in column A and you want to paste every 4th
data point into B, starting with row 1, your code would look something like:

Sub everyFourth()

Dim i As Integer
Dim j As Integer

j = 1

For i = 1 To 30
Cells(i, 2).Value = Cells(j, 1).Value
j = j + 4
Next i

End Sub

This code goes through 30 rows in A. This number can be adjusted to suit
your needs.

"Shalebot" wrote:

How would I go about creating a macro to select and copy certain cells in a
column and get them to paste in a blank column back-to-back (ie: selecting
every fourth cell in a column and pasting it one after another in a new
column)?

I tried finding something like this in these and other discussion groups,
but I'm not sure what to even call it, so my ability to find what I'm trying
to describe on my own is virtually nonexistent.

Any help would be greatly appreciated.


Luke M

Copying Select Repeating Cells in a Column
 
Here's a basic setup of a macro with commented setup to help you out. Just
plug this into a macro, change your options as needed/desired, and you should
be good to go.


Sub CopyCells()
Dim xDest As Range, xStart As Range
'Starting cell
Set xStart = Range("A2")
'Start of destination
Set xDest = Range("B2")

'How many rows to skip each time?
OffsetRule = 4
'How many cells to copy, not counting start cell?
xAmount = 3

'Begin data copying
xDest.Value = xStart.Value
For i = 1 To xAmount
xDest.Offset(i, 0).Value = xStart.Offset(i * OffsetRule, 0).Value
Next

End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Shalebot" wrote:

How would I go about creating a macro to select and copy certain cells in a
column and get them to paste in a blank column back-to-back (ie: selecting
every fourth cell in a column and pasting it one after another in a new
column)?

I tried finding something like this in these and other discussion groups,
but I'm not sure what to even call it, so my ability to find what I'm trying
to describe on my own is virtually nonexistent.

Any help would be greatly appreciated.



All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com