Help

Shalbriri

Board Regular
Joined
Nov 4, 2010
Messages
93
Code:
Sheets("Sheet2").Select
Range("d2:E33").Offset(0, 0).Select
Selection.Copy
Range("D2:E33").Offset(0, 1).PasteSpecial
Range("C2:D33").Offset(0, 0).Select
Selection.Copy
Range("C2:D33").Offset(0, 1).PasteSpecial
This is my code, its perfectly fine, tho, if someone could help me out and give me pointers on how to make this code into a loop.
since i need to move 2 columns of data to the right, by one step.




The idea is to move data from C to D to E to F and so on.
but the procedure must be backwards, if you get my point.
http://imageshack.us
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try:
Code:
Sub MoveMyColumns ()
Dim i as Long, j as Long
j = Cells(1, Columns.Count).End(xlToLeft).Column - 2
For i = j to 3 Step -1
Range(cells(2,j), cells(33, j + 1)).copy
cells(2,j+1).PasteSpecial
Next i
End Sub
 
Last edited:
Upvote 0
if you work backwards and copy f to d then d to c will you not just put column f in every column?
 
Upvote 0
Also just a quick note... you almost never need to use select. So your original code can also be:

Code:
Range("d2:E33").Offset(0, 0).Copy
Range("D2:E33").Offset(0, 1).PasteSpecial
Range("C2:D33").Offset(0, 0).Copy
Range("C2:D33").Offset(0, 1).PasteSpecial

Just something I picked up along the way.

Hope it helps.

AMAS
 
Upvote 0
Shalbriri said:
The idea is to move data from C to D to E to F and so on.
but the procedure must be backwards, if you get my point.

sry i miss led you, the first part is the one i am looking for.
C to D
D to E
E to F
F to infinity
 
Upvote 0
If you move C to D and then D to E, why not just move C to E??
 
Upvote 0
that just moves it the other way so every column would be c

you need to select the whole range and move it accross one at the same time
 
Upvote 0
Im so sorry guys this concept overall doesn't help me at all, since the idea was that the values under D are the starting value of products in storage, and C would've been the status value of the moment, and when ever new items were to be inserted into the storage the at the moment values would've become the starting values.

And the reason why it doesn't help me is that new items come randomly in a month. So it would've moved all the data and would've left empty gaps in the worksheet ...
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,086
Members
448,944
Latest member
sharmarick

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