ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copying every other row (https://www.excelbanter.com/excel-programming/391333-copying-every-other-row.html)

[email protected]

copying every other row
 
Hi All
I have data in column A1 to A2564. I want to take every other line
ie(A1, A3, A5, etc) and copy that to match the even columns in column
B. ie (A2 would go into B1, A4 would go into B3, etc.
So it is taking the value in every other line and copying it and
moving it up one cell and over one cell.
Thanks!
Roy

Example
A1 1
A2 2
A3 3
A4 4

Result
Al 1 B1 2
A2 now blank
A3 3 B3 3
A4 blank now


drhalter

copying every other row
 
Sounds like a lot of work to do each one with the mouse! If I understand
correctly you want to move data from A2 to B1, A4 to B3, and etc.. You do
not want to leave data in A2, A4, A6, etc. I have this code setting A2, A4,
A6 etc to Empty, which effectively deletes the content in those cells.

try this: in a module of VB...

Private Sub moveitems()

Dim n As Integer
n = 1
Do Until n 2654
Cells(n, 2) = Cells(n + 1, 1) 'move the data
Cells(n + 1, 1) = Empty 'delete the original data
n = n + 2 'increase the counter by two to
get every other line
Loop


End Sub


" wrote:

Hi All
I have data in column A1 to A2564. I want to take every other line
ie(A1, A3, A5, etc) and copy that to match the even columns in column
B. ie (A2 would go into B1, A4 would go into B3, etc.
So it is taking the value in every other line and copying it and
moving it up one cell and over one cell.
Thanks!
Roy

Example
A1 1
A2 2
A3 3
A4 4

Result
Al 1 B1 2
A2 now blank
A3 3 B3 3
A4 blank now




All times are GMT +1. The time now is 05:42 PM.

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