Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA code for moving data from even rows to columns after data in oddrows

I have a spreadsheet in Excel 2003. I have data in cells A1 thru
J3950. I want to move the data in every other row (the even rows) to
the odd rows, after the existing data in the odd rows. The data in
the odd rows ends in column J. So I want to move the data from
columns A to H in the even rows to columns K to R in the odd rows.
My worksheet is Sheet2a

This is my code:

Sub ShiftEvenRows()

With Worksheets("Sheet2a")
For i = 2 To 6950 Step 2
Set r2 = .Range("A(i):J(i)")
Set r1 = .Range("K(i-1):R(i-1)")
r1.Cut.r2

Next

End With
End Sub

I may have multiple errors. I get the error message "Subscript out of
Range."

Any help would be appreciated.

If anyone is willing to contact me off-line, my email addresses a



and



Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code for moving data from even rows to columns after data in odd rows

I think this will do what you want...

Sub EvenToOddRows()
Dim X As Long
Dim LastRow As Long
Dim Evens As Range
With Worksheets("Sheet1")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
For X = 2 To LastRow Step 2
.Range("A" & X & ":J" & X).Copy .Cells(X - 1, "K")
.Range("A" & X & ":J" & X).Clear
Next
End With
End Sub

Note: I made the assumption that the number of rows of data could vary and
set the code up to work down to the last row of data.

Rick


"Steve G" wrote in message
...
I have a spreadsheet in Excel 2003. I have data in cells A1 thru
J3950. I want to move the data in every other row (the even rows) to
the odd rows, after the existing data in the odd rows. The data in
the odd rows ends in column J. So I want to move the data from
columns A to H in the even rows to columns K to R in the odd rows.
My worksheet is Sheet2a

This is my code:

Sub ShiftEvenRows()

With Worksheets("Sheet2a")
For i = 2 To 6950 Step 2
Set r2 = .Range("A(i):J(i)")
Set r1 = .Range("K(i-1):R(i-1)")
r1.Cut.r2

Next

End With
End Sub

I may have multiple errors. I get the error message "Subscript out of
Range."

Any help would be appreciated.

If anyone is willing to contact me off-line, my email addresses a



and



Thank you in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VBA code for moving data from even rows to columns after data in odd rows

And yet another way -

Sub test()

With Worksheets("Sheet1")
.Range("A2:H3950").Copy .Range("K1:R3949")
For i = 2 To 3950 Step 2
.Range(.Cells(i, 1), .Cells(i, 18)).Clear
Next
End With

End Sub


I notice in your code you loop to 6950, adapt the above to suit (not least
the sheet name).


Regards,
Peter T



"Steve G" wrote in message
...
I have a spreadsheet in Excel 2003. I have data in cells A1 thru
J3950. I want to move the data in every other row (the even rows) to
the odd rows, after the existing data in the odd rows. The data in
the odd rows ends in column J. So I want to move the data from
columns A to H in the even rows to columns K to R in the odd rows.
My worksheet is Sheet2a

This is my code:

Sub ShiftEvenRows()

With Worksheets("Sheet2a")
For i = 2 To 6950 Step 2
Set r2 = .Range("A(i):J(i)")
Set r1 = .Range("K(i-1):R(i-1)")
r1.Cut.r2

Next

End With
End Sub

I may have multiple errors. I get the error message "Subscript out of
Range."

Any help would be appreciated.

If anyone is willing to contact me off-line, my email addresses a



and



Thank you in advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default thank you to Rick Rothstein and Peter T regarding VBA code for movingdata from even rows to columns after data in odd rows

On Jun 30, 4:13*pm, "Peter T" <peter_t@discussions wrote:
And yet another way -

Sub test()

With Worksheets("Sheet1")
* * .Range("A2:H3950").Copy .Range("K1:R3949")
* * For i = 2 To 3950 Step 2
* * * * .Range(.Cells(i, 1), .Cells(i, 18)).Clear
* * Next
End With

End Sub

I notice in your code you loop to 6950, adapt the above to suit (not least
the sheet name).

Regards,
Peter T

"SteveG" wrote in message

...



I have a spreadsheet in Excel 2003. *I have data in cells A1 thru
J3950. *I want to move the data in every other row (the even rows) to
the odd rows, after the existing data in the odd rows. *The data in
the odd rows ends in column J. *So I want to move the data from
columns A to H in the even rows to columns K to R in the odd rows.
*My worksheet is Sheet2a


This is my code:


Sub ShiftEvenRows()


With Worksheets("Sheet2a")
For i = 2 To 6950 Step 2
Set r2 = .Range("A(i):J(i)")
Set r1 = .Range("K(i-1):R(i-1)")
r1.Cut.r2


Next


End With
End Sub


I may have multiple errors. *I get the error message "Subscript out of
Range."


Any help would be appreciated.


If anyone is willing to contact me off-line, my email addresses a




and




Thank you in advance.- Hide quoted text -


- Show quoted text -


To : Rick Rothstein and Peter T--

I will try your code tomorrow. Thank you both very much.

Sincerely,

Steve Greenspan
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA code for moving data from even rows to columns after data inodd rows

On Jun 30, 1:14*pm, "Rick Rothstein \(MVP - VB\)"
wrote:
I think this will do what you want...

Sub EvenToOddRows()
* Dim X As Long
* Dim LastRow As Long
* Dim Evens As Range
* With Worksheets("Sheet1")
* * LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
* * For X = 2 To LastRow Step 2
* * * .Range("A" & X & ":J" & X).Copy .Cells(X - 1, "K")
* * * .Range("A" & X & ":J" & X).Clear
* * Next
* End With
End Sub

Note: I made the assumption that the number of rows of data could vary and
set the code up to work down to the last row of data.

Rick

"Steve G" wrote in message

...



I have a spreadsheet in Excel 2003. *I have data in cells A1 thru
J3950. *I want to move the data in every other row (the even rows) to
the odd rows, after the existing data in the odd rows. *The data in
the odd rows ends in column J. *So I want to move the data from
columns A to H in the even rows to columns K to R in the odd rows.
My worksheet is Sheet2a


This is my code:


Sub ShiftEvenRows()


With Worksheets("Sheet2a")
For i = 2 To 6950 Step 2
Set r2 = .Range("A(i):J(i)")
Set r1 = .Range("K(i-1):R(i-1)")
r1.Cut.r2


Next


End With
End Sub


I may have multiple errors. *I get the error message "Subscript out of
Range."


Any help would be appreciated.


If anyone is willing to contact me off-line, my email addresses a




and




Thank you in advance.- Hide quoted text -


- Show quoted text -


Mr. Rothstein--

I just wanted to thank you. I ran the macro you wrote for me last
wek. It worked flawlessly. If you ever need a favor in the Washinton
DC area, please let me know. Thank you again. Steve Greenspan


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving data from row to columns gauche8715 New Users to Excel 2 November 8th 08 03:35 AM
Moving data between columns CW Excel Discussion (Misc queries) 7 July 24th 08 07:15 PM
moving duplicate data in rows to columns with same name Jennifer B. Excel Discussion (Misc queries) 2 June 25th 08 03:47 PM
Moving Data from Rows to Columns Josue Preciado Excel Programming 1 October 24th 06 06:38 PM
Moving data from 3 columns to next 3 macke Excel Programming 0 March 14th 06 03:54 PM


All times are GMT +1. The time now is 02:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"